codeforces G - 2^Sort 滑动窗口+队列
求满足以上条件的i的个数
显然是队列的题(甚至只要维护head和tail,连队列的数组都不用开hhh
#include<bits/stdc++.h> using namespace std; int n,k,a[3*int(1e5)]; void solve(){ cin>>n>>k; for(int i=1;i<=n;i++) cin>>a[i]; int head=1,tail=0,ans=0; for(int i=1;i<=n;i++) { //cout<<i<<" "<<head<<" "<<tail<<" "<<endl; if(a[i]*2>a[i-1]) { //rudui tail++; if(tail-head==k) { // cout<<head<<" "<<tail<<" "; ans++; //cout<<ans<<endl; head++; } } else { while(head<tail) head++; } } cout<<ans<<endl; } int main(){ //freopen("lys.in","r",stdin); int t; cin>>t; while(t--){ solve(); } }