hdu_5806_NanoApe Loves Sequence Ⅱ(双指针)
题目链接:hdu_5806_NanoApe Loves Sequence Ⅱ
题意:
给你一段数,问你有多少个区间满足第K大的数不小于m
题解:
直接双指针加一下区间就行
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<algorithm> 3 #define F(i,a,b) for(int i=a;i<=b;i++) 4 using namespace std; 5 typedef long long ll; 6 const int N=2e5+7; 7 int t,n,k,m; 8 int a[N]; 9 int main() 10 { 11 scanf("%d",&t); 12 while(t--) 13 { 14 scanf("%d%d%d",&n,&m,&k); 15 F(i,1,n)scanf("%d",a+i); 16 int l=1,r=0,all=0; 17 ll ans=0; 18 while(r<n) 19 { 20 while(r<n&&all<k) 21 { 22 r++; 23 if(a[r]>=m)all++; 24 } 25 if(r==n&&all<k)break; 26 if(all==k)ans+=n-r+1; 27 while(all==k) 28 { 29 if(a[l]>=m)all--; 30 l++; 31 if(all==k)ans+=n-r+1; 32 } 33 } 34 printf("%I64d\n",ans); 35 } 36 return 0; 37 }