呼~终于发了个有意义的题解
#include<bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
int read(){
int r=0,f=1;char c=getchar();
while((c<'0'||c>'9')&&c^'-')c=getchar();
if(c=='-')f=-1,c=getchar();
while(c>='0'&&c<='9')r=(r<<1)+(r<<3)+c-'0',c=getchar();
return r*f;
}
ll n,k;
deque<ll>q,p;
ll a[1000005];
int main(){
n=read(),k=read();
for(ll i=1;i<=n;i++){
a[i]=read();
}
for(ll i=1;i<=n;i++){
if(!q.empty()){
while(!q.empty()&&a[i]>=q.back()){
q.pop_back();
p.pop_back();
}
q.push_back(a[i]);
p.push_back(i);
if((p.front()+k)<=i){
q.pop_front();
p.pop_front();
}
}else{
q.push_back(a[i]);
p.push_back(i);
}
if(i>=k){
cout<<q.front()<<endl;
}
}
return 0;
}