其他分享
首页 > 其他分享> > P2032 扫描

P2032 扫描

作者:互联网


#include <bits/stdc++.h>
#define re register
using namespace std;

const int N=2e6+5;
int n,k;
int a[N];
int head, tail;
int q[N];

void monotoneMax(){
    head=1, tail=0;
    for(re int i=1;i<=n;i++){
        while(head<=tail && a[q[tail]]<=a[i]) tail--;
        q[++tail]=i;
        while(head<=tail && q[head]+k<=i) head++;
        if(i>=k) cout<<a[q[head]]<<endl;
    }
}

int main()
{
    ios::sync_with_stdio(0);
    clock_t c1 = clock();
#ifdef LOCAL
    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);
#endif
    // ======================================================================
    cin>>n>>k;
    for(re int i=1;i<=n;i++) cin>>a[i];
    monotoneMax();

    // ======================================================================
end:
    cerr << "Time Used:" << clock() - c1 << "ms" << endl;
    return 0;
}

标签:std,head,P2032,int,扫描,monotoneMax,re,tail
来源: https://www.cnblogs.com/syqwq/p/15153816.html