hdu NanoApe Loves Sequence Ⅱ

21 篇文章 0 订阅
7 篇文章 0 订阅

NanoApe Loves Sequence Ⅱ

Accepts: 235
Submissions: 396
Time Limit: 4000/2000 MS (Java/Others)
Memory Limit: 262144/131072 K (Java/Others)
Problem Description

NanoApe, the Retired Dog, has returned back to prepare for for the National Higher Education Entrance Examination!

In math class, NanoApe picked up sequences once again. He wrote down a sequence withnnn numbers and a number mmm on the paper.

Now he wants to know the number of continous subsequences of the sequence in such a manner that thekkk-th largest number in the subsequence is no less than mmm.

Note : The length of the subsequence must be no less than kkk.

Input

The first line of the input contains an integer TTT, denoting the number of test cases.

In each test case, the first line of the input contains three integers n,m,kn,m,kn,m,k.

The second line of the input contains nnn integers A1,A2,...,AnA_1, A_2, ..., A_nA1,A2,...,An, denoting the elements of the sequence.

1≤T≤10, 2≤n≤200000, 1≤k≤n/2, 1≤m,Ai≤1091 \le T \le 10,~2 \le n \le 200000,~1 \le k \le n/2,~1 \le m,A_i \le 10^91T10, 2n200000, 1kn/2, 1m,Ai109

Output

For each test case, print a line with one integer, denoting the answer.

Sample Input
1
7 4 2
4 2 7 7 6 5 1
Sample Output
18

求总共有几个子区间满足区间内第k大数不小于m

记录大于等于m的数的位置  从左往右看 对于一段区间来说,如果i-j区间内有了k个不小于m的数  那么这个区间能组成 左边到上一个不小于k的数的长度+1 乘上 右边剩余的数的个数 个区间

/************************************************
┆  ┏┓   ┏┓ ┆
┆┏┛┻━━━┛┻┓ ┆
┆┃       ┃ ┆
┆┃   ━   ┃ ┆
┆┃ ┳┛ ┗┳ ┃ ┆
┆┃       ┃ ┆
┆┃   ┻   ┃ ┆
┆┗━┓    ┏━┛ ┆
┆  ┃    ┃  ┆      
┆  ┃    ┗━━━┓ ┆
┆  ┃  AC代马   ┣┓┆
┆  ┃           ┏┛┆
┆  ┗┓┓┏━┳┓┏┛ ┆
┆   ┃┫┫ ┃┫┫ ┆
┆   ┗┻┛ ┗┻┛ ┆
************************************************ */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#define ll long long
using namespace std;

ll a[200010],Max[200010];

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m,k;
        scanf("%d%d%d",&n,&m,&k);
        int num=0,len=0;
        ll ans=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            if(num<k)
            {
                if(a[i]>=m)
                {
                    Max[num++]=i;
                }
                if(num==k)
                {
                    ans+=(n-i+1)*(Max[0]);
                }
            }
            else if(a[i]>=m)
            {
                Max[num++]=i;
                len=num-k;
                ll l=Max[len]-Max[len-1];
                ll r=n-i+1;
                ans+=l*r;
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值