题目链接: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. HDU2539:点球大战

    Problem Description 在足球比赛中,有不少赛事,例如世界杯淘汰赛和欧洲冠军联赛淘汰赛中,当比赛双方经过正规比赛和加时赛之后仍然不分胜负时,需要进行点球大战来决定谁能够获得最终的胜利. ...

  2. jsp第1讲(上集)

    jsp讲解框架 (一)Java EE核心十三种技术介绍 (二)Java EE程序员修炼成精的法门 (三)jsp版本的用户管理系统演示 (四)jsp概述 (五)jsp的运行原理 (六)jsp版的计算器 ...

  3. R语言笔记3--实例1

    综合性例子: 模拟产生统计专业同学的名单(学号区分),记录数学分析,线性代数.概率统计三科成绩,然后进行一些统计分析 1.首先产生一个向量(100个元素,代表100位学生) 2.模拟成绩 runif: ...

  4. 获取sql执行时间

    sql server中获取要执行的sql或sql块的执行时间,方法之一如下: declare @begin datetime,@end datetime set @begin =getdate() - ...

  5. 【字母全排列】 poj 1256

    深搜   注意与STL模版的去重函数唯一的区别就是有去重. #include <iostream> #include <cstdio> #include <string. ...

  6. 如何使用Android中的OpenGL ES媒体效果

    引自:http://www.2cto.com/kf/201506/404366.html Android的媒体效果框架允许开发者可以很容易的应用多种令人印象深刻的视觉效果到照片或视频之上.作为这个媒体 ...

  7. linux(视频学习)2

    第二部分(javaee的开发环境的搭建): 1. 安装jdk的过程: 安装ios的镜像文件,挂载到/mnt目录下.挂载: mount  /mnt/cdrom卸载: umount  /mnt/cdrom ...

  8. sql 日结

    --生成日结数据 ==================================== -- Author: <Author,,Name> -- Create date: <Cr ...

  9. js滚动条

    /*滚动条在Y轴上的滚动距离*/function ScrollTop(){ var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0; i ...

  10. java 文件字节输入流

    Example10_4.java import java.io.*; public class Example10_4 { public static void main(String args[]) ...