5806 NanoApe Loves Sequence Ⅱ(尺取法)
NanoApe Loves Sequence Ⅱ
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/131072 K (Java/Others)
Total Submission(s): 1585 Accepted Submission(s): 688
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 Output
17 4 24 2 7 7 6 5 1
Sample Output
18
思路
题意:
退役狗 NanoApe 滚回去学文化课啦! 在数学课上,NanoApe 心痒痒又玩起了数列。他在纸上随便写了一个长度为 n 的数列,他又根据心情写下了一个数 m。 他想知道这个数列中有多少个区间里的第 k 大的数不小于 m,当然首先这个区间必须至少要有 k 个数啦。
题解:求数列中多少个区间第k大不小于m,那么我们可以把数列中大于等于m的位置置1,其余置0,那么利用尺取法从头开始扫,找到每个位置开始和为k的区间的末位置,那么就知道总共有多少个区间了
#include<bits/stdc++.h>
using namespace std;
typedef __int64 LL;
const int maxn = 200005;
int num[maxn];
int main()
{
//freopen("input.txt","r",stdin);
int T;
scanf("%d",&T);
while (T--)
{
int n,m,k,tmp;
scanf("%d%d%d",&n,&m,&k);
for (int i = 0;i < n;i++)
{
scanf("%d",&tmp);
num[i] = tmp >= m?1:0;
}
int s = 0,t = 0;
LL res = 0,sum = 0;
for (;;)
{
while (t < n && sum < k)
{
sum += num[t++];
}
if (sum < k) break;
res += n - t + 1;
sum -= num[s++];
}
printf("%I64d\n",res);
}
return 0;
}
5806 NanoApe Loves Sequence Ⅱ(尺取法)的更多相关文章
- NanoApe Loves Sequence Ⅱ(尺取法)
题目链接:NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/131072 ...
- hdu-5806 NanoApe Loves Sequence Ⅱ(尺取法)
题目链接: NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/13107 ...
- HDU5806:NanoApe Loves Sequence Ⅱ(尺取法)
题目链接:HDU5806 题意:找出有多少个区间中第k大数不小于m. 分析:用尺取法可以搞定,CF以前有一道类似的题目. #include<cstdio> using namespace ...
- Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) (C++,Java)
Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) Hdu 5806 题意:给出一个数组,求区间第k大的数大于等于m的区间个数 #include<queue> # ...
- HDU 5806 NanoApe Loves Sequence Ⅱ (模拟)
NanoApe Loves Sequence Ⅱ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5806 Description NanoApe, t ...
- HDU 5806 NanoApe Loves Sequence Ⅱ ——(尺取法)
题意:给出一个序列,问能找出多少个连续的子序列,使得这个子序列中第k大的数字不小于m. 分析:这个子序列中只要大于等于m的个数大于等于k个即可.那么,我们可以用尺取法写,代码不难写,但是有些小细节需要 ...
- HDU 5806 NanoApe Loves Sequence Ⅱ
将大于等于m的数改为1,其余的改为0.问题转变成了有多少个区间的区间和>=k.可以枚举起点,二分第一个终点 或者尺取法. #pragma comment(linker, "/STACK ...
- HDU - 5806 NanoApe Loves Sequence Ⅱ 想法题
http://acm.hdu.edu.cn/showproblem.php?pid=5806 题意:给你一个n元素序列,求第k大的数大于等于m的子序列的个数. 题解:题目要求很奇怪,很多头绪但写不出, ...
- HDU 5806 - NanoApe Loves Sequence Ⅱ (BestCoder Round #86)
若 [i, j] 满足, 则 [i, j+1], [i, j+2]...[i,n]均满足 故设当前区间里个数为size, 对于每个 i ,找到刚满足 size == k 的 [i, j], ans + ...
随机推荐
- 学习笔记 UpdateXml() MYSQL显错注入
在学习之前,需要先了解 UpdateXml() . UPDATEXML (XML_document, XPath_string, new_value); 第一个参数:XML_document是Stri ...
- Android事件分发机制浅谈(三)--源码分析(View篇)
写事件分发源码分析的时候很纠结,网上的许多博文都是先分析的View,后分析ViewGroup.因为我一开始理解的时候是按我的流程图往下走的,感觉方向很对,单是具体分析的时候总是磕磕绊绊的,老要跳到Vi ...
- lucky 的 时光助理(2)
lucky小姐说:昨天晚上他喝醉了,发消息说他想我了,说他后悔了. 我很惊讶. 我问lucky:你们很久都没有联系, 突然说... 你怎么想. 没错,'他'就是lucky的前男友. lucky看着我, ...
- [Python核心编程] 第1章 欢迎来到Python世界
什么是Python Python的起源 Python的特点 下载Python 安装Python 运行Python Python文档 比较Python 其他实现 1.什么是Python ...
- 为什么现在我最终推荐内存OLTP
在今年的8月份,我写了篇文章,介绍了我还不推荐用户使用内存OLTP的各个理由.近日很多人告诉我,他们有一些性能的问题,并考虑使用内存OLTP来解决它们. 众所皆知,在SQL Server里内存OLTP ...
- 查找素数Eratosthenes筛法的mpi程序
思路: 只保留奇数 (1)由输入的整数n确定存储奇数(不包括1)的数组大小: n=(n%2==0)?(n/2-1):((n-1)/2);//n为存储奇数的数组大小,不包括基数1 (2)由数组大小n.进 ...
- MySQL 数据库的备份与恢复
一.MySQL 常见的备份方式 1. 直接拷贝数据库文件(物理拷贝) 2. 使用 mysqldump 工具备份 3. 使用 mysqlhotcopy 工具备份 4. 使用 mysql 的主从同步复制, ...
- java中可定制的序列化过程 writeObject与readObject
来源于:[http://bluepopopo.iteye.com/blog/486548] 什么是writeObject 和readObject?可定制的序列化过程 这篇文章很直接,简单易懂.尝试着翻 ...
- [No0000A3]护眼谎言大揭秘,选择正确的方式保护眼睛!
当眼睛因为过度劳累而状况频出的时候,许多人没有选择极目远眺.眼保健操.充分睡眠等简单易行的养眼方式,而是求助于各种护眼工具.于是,在视疲劳成为常见眼病之后,护眼市场产品层出不穷:护眼灯.眼贴.眼保仪. ...
- BZOJ 3144: [Hnoi2013]切糕
3144: [Hnoi2013]切糕 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1495 Solved: 819[Submit][Status] ...