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();
    }
}
复制代码

 

posted @   liyishui  阅读(50)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示