NanoApe Loves Sequence Ⅱ

题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=5806

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


##题意:

求满足以下条件的连续子串的数目:
子串中第k大的数比m大.


##题解:

要维护第k大的数估计很麻烦,这里转换一下思路:
满足条件的子串中大于m的数的个数大于等于k.
先把数串中大于m的数的位置全部记录下来, pos[i]是第i个比m大的数.
对于i,对必定包含pos[i]~pos[i+k-1]这k个数的连续子串计数即可.


##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define eps 1e-8
#define maxn 201000
#define mod 1000000007
#define inf 0x3f3f3f3f
#define mid(a,b) ((a+b)>>1)
#define IN freopen("in.txt","r",stdin);
using namespace std;

int n,m,k;

LL pos[maxn], cnt;

int main(void)

{

//IN;

int t; cin >> t;
while(t--)
{
cnt = 0;
cin >> n >> m >> k;
for(int i=1; i<=n; i++) {
int x; scanf("%d", &x);
if(x >= m) pos[++cnt] = (LL)i;
} LL ans = 0;
for(int i=1; i<=cnt; i++) {
if(i+k-1 > cnt) break;
ans += (pos[i]-pos[i-1]) * (n-pos[i+k-1]+1);
} printf("%lld\n", ans);
} return 0;

}

HDU 5806 NanoApe Loves Sequence Ⅱ (模拟)的更多相关文章

  1. Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) (C++,Java)

    Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) Hdu 5806 题意:给出一个数组,求区间第k大的数大于等于m的区间个数 #include<queue> # ...

  2. HDU - 5806 NanoApe Loves Sequence Ⅱ 想法题

    http://acm.hdu.edu.cn/showproblem.php?pid=5806 题意:给你一个n元素序列,求第k大的数大于等于m的子序列的个数. 题解:题目要求很奇怪,很多头绪但写不出, ...

  3. 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 + ...

  4. HDU 5806 NanoApe Loves Sequence Ⅱ

    将大于等于m的数改为1,其余的改为0.问题转变成了有多少个区间的区间和>=k.可以枚举起点,二分第一个终点 或者尺取法. #pragma comment(linker, "/STACK ...

  5. HDU 5806 NanoApe Loves Sequence Ⅱ ——(尺取法)

    题意:给出一个序列,问能找出多少个连续的子序列,使得这个子序列中第k大的数字不小于m. 分析:这个子序列中只要大于等于m的个数大于等于k个即可.那么,我们可以用尺取法写,代码不难写,但是有些小细节需要 ...

  6. HDU 5805 NanoApe Loves Sequence (模拟)

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

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

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

  8. HDU 5805 NanoApe Loves Sequence (思维题) BestCoder Round #86 1002

    题目:传送门. 题意:题目说的是求期望,其实翻译过来意思就是:一个长度为 n 的数列(n>=3),按顺序删除其中每一个数,每次删除都是建立在最原始数列的基础上进行的,算出每次操作后得到的新数列的 ...

  9. HDU 5805 - NanoApe Loves Sequence (BestCoder Round #86)

    先找相邻差值的最大,第二大,第三大 删去端点会减少一个值, 删去其余点会减少两个值,新增一个值,所以新增和现存的最大的值比较一下取最大即可 #include <iostream> #inc ...

随机推荐

  1. Android开发之Okhttp:java.lang.IllegalStateException: closed

    在使用Okhttp的时候 运行到response.body().string()一步时抛异常,java.lang.IllegalStateException: closed 查阅各种资料大致意思是Th ...

  2. Android开发之事件分发和Listener

    参考:http://blog.csdn.net/zhongkejingwang/article/details/38141719 http://blog.csdn.net/zhongkejingwan ...

  3. bzoj2324营救皮卡丘

    费用流. 建图比较重要. 1.S->id[0][0] flow=k. 表示k条路径. 2.S->id[i][0] flow=1, 每次消耗1流量就补充1流量. 3.id[i][1]-> ...

  4. CodeForces 489B (贪心 或 最大匹配) BerSU Ball

    题意: 有m个男孩和n个女孩,每个人都有一个舞蹈熟练度,用一个不超过100的正整数来表示. 一个男孩和一个女孩能够结为舞伴当且仅当两人的熟练度相差不超过1. 问最多能结成多少对舞伴 分析: 这是一个二 ...

  5. 待实践二:MVC3下的3种验证 (1)前台 jquery validate验证 (2)MVC实体验证 (3)EF生成的/自己手写的 自定义实体校验(伙伴类+元素据共享)

    MVC3下的3种验证 (1):前台Jquery Validate脚本验证 引入脚本 <script src="../js/jquery.js" type="text ...

  6. 英文 数字 不换行 撑破div容器

    我们在div等容器 中,如果规定了宽度,并且里面的内容不是全英文或者全数字是OK的,会自动换行,但是如果是全数字或者是全英文,则会撑破容器,如图     解决方法 word-wrap:break-wo ...

  7. Java [Leetcode 203]Remove Linked List Elements

    题目描述: Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> ...

  8. Android02--debug.keystore的注册信息

    1 -- 签名文件的密钥 默认签名文件的密码是:android 该文件的存放点是: 2 -- 签名文件的签名信息 keytool -list -v -keystore C:\Users\motadou ...

  9. 【转】Android fill_parent和wrap_content分析

    fill_parent设置一个顶部布局或控件强制性让它布满整个屏幕. wrap_content布局指根据视图内部内容自动扩展以适应其大小. 1. wrap_content <?xml versi ...

  10. OutputFormat中OutputCommitter解析

    在hadoop中,由于一个Task可能由多个节点同时运行,当每个节点完成Task时,一个Task可能会出现多个结果,为了避免这种情况的出现,使用了OutPutCommitter.所以OutPutCom ...