cf 1840c

                                                      c. Ski Resort

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Dima Vatrushin is a math teacher at school. He was sent on vacation for n� days for his good work. Dima has long dreamed of going to a ski resort, so he wants to allocate several consecutive days and go skiing. Since the vacation requires careful preparation, he will only go for at least k� days.

You are given an array a� containing the weather forecast at the resort. That is, on the i�-th day, the temperature will be ai�� degrees.

Dima was born in Siberia, so he can go on vacation only if the temperature does not rise above q� degrees throughout the vacation.

Unfortunately, Dima was so absorbed in abstract algebra that he forgot how to count. He asks you to help him and count the number of ways to choose vacation dates at the resort.

Input

The first line of the input contains an integer t� (1≤t≤1041≤�≤104) — the number of test cases.

Then follow the descriptions of the test cases.

The first line of each test case contains three integers n�, k�, q� (1≤n≤2⋅1051≤�≤2⋅105, 1≤k≤n1≤�≤�, −109≤q≤109−109≤�≤109) — the length of the array a�, the minimum number of days at the resort, and the maximum comfortable temperature for Dima.

The second line of each test case contains n� integers a1,a2,a3,…,an�1,�2,�3,…,�� (−109≤ai≤109−109≤��≤109) — the temperature at the ski resort.

The sum of all n� values over all test cases does not exceed 2⋅1052⋅105.

Output

Output t� integers, each of which is the answer to the corresponding test case — the number of ways for Dima to choose vacation dates at the resort.

Example

input

Copy

 

7

3 1 15

-5 0 -10

5 3 -33

8 12 9 0 5

4 3 12

12 12 10 15

4 1 -5

0 -1 2 5

5 5 0

3 -1 4 -5 -3

1 1 5

5

6 1 3

0 3 -2 5 -4 -4

output

Copy

6
0
1
0
0
1
9

Note

In the first test case of the example, Dima can go on any day, so the suitable dates for him are [1], [2], [3], [1, 2], [2, 3], [1, 2, 3].

In the second and fourth test cases of the example, Dima cannot go on any day due to the high temperature, so there are no suitable dates.

In the third test case of the example, Dima can only go on the dates [1, 2, 3].

大体可以理解为 一串数字如果有子串满足大于q的数,只要其个数要大于k,便用排列组合计算其的组成个数。

思路:

1. 可以先遍历一遍数组,满足条件就把计数器加上1。

2.当遇到不满足的时,就把之前满足条件的字串进行计算,并且计数器清零。

3.最后在遍历完后再进行一次判定。

考察知识点:

1.组合数学。 

2.对于数组字串的处理,计数器的应用。

代码实现:

#include <bits/stdc++.h>
using namespace std;
int t;

void solve()
{
    int n,k,q;
    cin>>n>>k>>q;
    int a[200010];
    long long  cnt=0,ans=0;
    for (int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]<=q){
            cnt++;
        }
        else {
            if(cnt>=k){
                ans+=(cnt-k+1)*(cnt-k+2)/2;
                
            }
            cnt=0;
        }
    }
    if(cnt>=k){
        ans+=(cnt-k+1)*(cnt-k+2)/2;
    }
    cout<<ans<<endl;
    
}

int main()
{
    cin>>t;
    while(t--){
        solve();
    }
    
}

注意:
1.计数器要清零和不是变为一。

2.开long long 防止数据爆int. 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值