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. UVA 11916 Emoogle Grid(同余模)

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  2. css link和@import区别用法

    这里link与@import介绍的是html引入css的语法单词.两者均是引入css到html的单词. 1.link语法结构<link rel="stylesheet" ty ...

  3. [LeetCode#267] Palindrome Permutation II

    Problem: Given a string s, return all the palindromic permutations (without duplicates) of it. Retur ...

  4. volicity语法学习和总结

    Velocity是一个基于java的模板引擎(template engine).它允许任何人仅仅简单的使用模板语言(template language)来引用由java代码定义的对象.当Velocit ...

  5. poi2012完成

    终于完成了(2798是我cheat的……),感觉poi的题好锻炼智商…… 截图留念,题解见博客中对应题号的解题报告

  6. 真正解决ASP.NET每一个页面首次访问超级慢的问题 (转载)

    原文:http://www.afuhao.com/article_articleId-219.shtml 摘要:ASP.NET页面首次打开很慢,但别的页面如果没有访问过,去访问也会慢.你也许认为它是在 ...

  7. temp - Linux administration handbook 答案

    我开始做第一章后的练习题,发觉不是很容易随意地回答,就像是C++ primer之后的练习题的感觉. 自己有这么多不会的,让我感觉很不爽啊- -! 先不要要求自己一下子都明了,一口吃不成胖子,先找一份工 ...

  8. Java [Leetcode 110]Balanced Binary Tree

    题目描述: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced b ...

  9. MVC中前台所得

    前台页面时间格式修改: @item.CreateTime.ToString("yyyy-MM-dd hh:mm:ss") 前台方法调用传参数: <a href="# ...

  10. UVA 10047 The Monocycle

    大白图论第二题··· 题意:独轮车的轮子被均分成五块,每块一个颜色,每走过一个格子恰好转过一个颜色. 在一个迷宫中,只能向前走或者左转90度或右转90度(我曾天真的认为是向左走和向右走···),每个操 ...