首页 > 其他 > 详细

hdu NanoApe Loves Sequence Ⅱ

时间:2016-08-06 20:36:06      阅读:228      评论:0      收藏: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 with nnn 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 the kkk-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_nA?1??,A?2??,...,A?n??, 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,A?i??10?9??

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;

int 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;
}


hdu NanoApe Loves Sequence Ⅱ

原文:http://blog.csdn.net/u013097262/article/details/52138255

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!