主题

主题

 
   

NanoApe Loves Sequence Ⅱ

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

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≤10^9

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的序列,给出一个k与m。求有多少个子区间满足这个子区间中第k的数大于或者等于m。


个人解法:

据说官方题解是啥尺取法?

我的想法很简单。第k大的数大于或者等于m,也就是说这个区间存在k个大于或者等于m的数字。我们枚举左端点,二分查找右端点即可。


代码如下:

https://code.csdn.net/snippets/2311026

 
 
评论