dddl样例通过,不慎爆0(

P1440 求m区间内的最小值

Yikara @ 2021-10-22 21:06:40

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=2e6+1;
int n,k;
struct s{
    int d,v;
}a[maxn];
deque <s>q;
void up(){
    cout<<0<<"\n"<<a[1].v<<"\n";
    for(int i=2;i<=n;i++){
        while(!q.empty()&&a[i-1].v<=q.front().v){
            q.pop_front();
        }
        q.push_front(a[i-1]);
        while(q.back().d<=i-1-k)q.pop_back();
        if(i-1>=k)cout<<q.back().v<<"\n";
    }
}
void read(){
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i].v;
        a[i].d=i;
    }
}
signed main(){
    ios::sync_with_stdio(false);
    read();
    up();
    return 0;
}

|