题目链接:NanoApe Loves Sequence Ⅱ

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others)
Total Submission(s): 339    Accepted Submission(s): 165

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 n numbers and a number m on the paper.

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

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

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

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

The second line of the input contains n integers A1,A2,...,An, denoting the elements of the sequence.

1≤T≤10, 2≤n≤200000, 1≤k≤n/2, 1≤m,Ai≤109

 
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
 
题解:
前缀和真是个好东西。前缀和可以是前n个的和,前n项的最小值,前n项的最大值。。。
这个题用到前n项大于m的个数。然后用个尺取法。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = ;
int a[maxn];
int prek[maxn];
int main()
{
int T;cin>>T;
while(T--)
{
int n,m,k;
cin>>n>>m>>k;
memset(prek,,sizeof(prek));
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
if(a[i]>=m) prek[i] += prek[i-]+;
else prek[i] = prek[i-];
}
long long ans = ;
int sum = ;
int t = ;
for(int l=;l<=n;l++)
{
while(t<=n&&sum<k)
{
sum = prek[t]-prek[l];
t++;
}
if(sum<k) break;
ans += (n-t+);
sum = prek[t-]-prek[l+];
}
printf("%I64d\n",ans);
}
return ;
}

NanoApe Loves Sequence Ⅱ(尺取法)的更多相关文章

  1. hdu-5806 NanoApe Loves Sequence Ⅱ(尺取法)

    题目链接: NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 262144/13107 ...

  2. HDU5806:NanoApe Loves Sequence Ⅱ(尺取法)

    题目链接:HDU5806 题意:找出有多少个区间中第k大数不小于m. 分析:用尺取法可以搞定,CF以前有一道类似的题目. #include<cstdio> using namespace ...

  3. 5806 NanoApe Loves Sequence Ⅱ(尺取法)

    传送门 NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K ...

  4. 5805 NanoApe Loves Sequence(想法题)

    传送门 NanoApe Loves Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/131072 K ( ...

  5. HDU 5806 NanoApe Loves Sequence Ⅱ (模拟)

    NanoApe Loves Sequence Ⅱ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5806 Description NanoApe, t ...

  6. HDU 5805 NanoApe Loves Sequence (模拟)

    NanoApe Loves Sequence 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5805 Description NanoApe, the ...

  7. Best Coder #86 1002 NanoApe Loves Sequence

    NanoApe Loves Sequence Accepts: 531 Submissions: 2481 Time Limit: 2000/1000 MS (Java/Others) Memory ...

  8. hdu-5805 NanoApe Loves Sequence(线段树+概率期望)

    题目链接: NanoApe Loves Sequence Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 262144/131072 ...

  9. HDU5806 NanoApe Loves Sequence Ⅱ

    NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (Ja ...

随机推荐

  1. Codeforces Round #350 (Div. 2)_D2 - Magic Powder - 2

    D2. Magic Powder - 2 time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. csuoj1009

    AC代码: #include <iostream>#include <iomanip>using namespace std;//计算数学期望值,可以自己直接通过数组的方式来实 ...

  3. SharePoint2013 Set Value To PeoplePicker

    var columnName = 'Display Name';var userName = 'domain\\name';var searchText = RegExp("FieldNam ...

  4. intent.putExtra()方法参数详解

    [开篇骂几句:fuck]1.扯淡intent.putExtra()怎么使用?2.胡说intent.putExtra(); [扯淡:其实你在问它怎么用的时候,你要明白,你知道不知道这是个什么东东,有必要 ...

  5. storm serializable

    http://www.programgo.com/article/68283366567/

  6. Toy Storage POJ 2398

    题目大意:和 TOY题意一样,但是需要对隔板从左到右进行排序,要求输出的是升序排列的含有i个玩具的方格数,以及i值. 题目思路:判断叉积,二分遍历 #include<iostream> # ...

  7. iOS8.0以后的相册

    在 iOS 8.0 后, 使用the Photos framework 代替 the Assets Library framework , The Photos framework 提供更特色和更好的 ...

  8. jquery 展开关闭效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. boost库之geometry

    环境:win732位旗舰版.VS2010旗舰版.boost 1.55.0版本.坐标系为MM_TEXT Geometry是一个开源的几何计算库,包含了几何图形最基本的操作(也支持复杂的操作),下面我们看 ...

  10. 华哥倒酒<区间标记,二分>

    题目链接 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; t ...