中级天翼
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<iomanip>
#include<list>
#include<stack>
using namespace std;
int n,k,a[1000005],q[1000005],h,t;
void push(int idx){
while(h!=t&&idx-q[h]>=k) h++;
while(h!=t&&a[q[t-1]]<=a[idx]) t--;
q[t++]=idx;
}
void push1(int idx){
while(h!=t&&idx-q[h]>=k) h++;
while(h!=t&&a[q[t-1]]>=a[idx]) t--;
q[t++]=idx;
}
int main(){
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=k;i<=n;i++){
push1(i);
}
for(int i=k;i<=n;i++){
push1(i);
cout<<a[q[h]]<<" ";
}
cout<<endl;
memset(q,0,sizeof(q));
h=t=0;
for(int i=1;i<k;i++){
push(i);
}
for(int i=k;i<=n;i++){
push(i);
cout<<a[q[h]]<<" ";
}
return 0;
}
黄子澄在2020-12-01 19:35:47追加了内容
@董子墨 @包涵宇