Nanoape Loves Sequenceⅱaccepts:374submissions:946Time limit:4000/2000 MS (java/others)Memory limit:262144/131072 K (java/others)Problem description
Retired dog Nanoape go back to learn culture Class! In math class, Nanoape heart itch and play a series. He wrote on a piece of paper a length ofNn the series, and he wrote down a number according to the moodm m. He wants to know how many bands in this sequence are kk Large number not less than mm, of course first this interval must have at least k k number.
Enter a description
First behavior a positive integerTT, which represents the number of data groups. First behavior for each set of data three integersNmkN,M,K. Second actNn integersAiA?I??, which represents this series.1t10 2n200000 1KN/2 1mai1091≤T≤10,2≤N≤200000,1≤K≤N/2, 1 ≤m, a ? Span class= "Reset-textstyle scriptstyle cramped" >i ?? ≤10 ? 9 ?
Output description
For each set of data output a single number represents the answer.
Input sample
17 4 24 2 7 7 6 5 1
Output sample
18
To know the name of Two-pointer.
The number of >=m is 1 and the other is 0, so how many intervals and >=k are there?
Sliding window, I is the head, p is the tail
////main.cpp//bc86-1003////Created by Candy on 10/1/16.//copyright©2016 Candy. All rights reserved.//#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<vector>#include<string>using namespacestd;Const intn=2e5+5; inlineintRead () {CharC=getchar ();intx=0, f=1; while(c<'0'|| C>'9'){if(c=='-') f=-1; c=GetChar ();} while(c>='0'&&c<='9') {x=x*Ten+c-'0'; c=GetChar ();} returnx;}intT,n,m,k,a[n];intMainintargcConst Char*argv[]) {T=read (); while(t--) {n=read (); M=read (); k=read (); for(intI=1; i<=n;i++) {a[i]=read (); A[i]=a[i]>=m?1:0;} intCnt=0, p=1; Long Longans=0; for(intI=1; i<=n-k+1; i++){ while(cnt<k&&p<=N) CNT+=a[p++]; if(cnt>=k) ans+= (Long Long) (n-p+1+1);//p already add 1cnt-=A[i]; } printf ("%lld\n", ans); } return 0;}
bc#86 1003NanoApe Loves Sequenceⅱ[two-pointer]