keep_ @ 2020-05-01 19:49:59
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=1e6+1;
int a[maxn],q[maxn],k,n;
long long Q[maxn];
void minn(){
int head=1;
int tail=2;
for(int i=1;i<=n;i++){
while(q[head]<=i-k)
head++;
while(head<=(tail-1)&&a[q[tail-1]]>a[i]){
tail--;
}
q[tail]=i;
tail++;
if(i>=k)
cout<<a[q[head]]<<" ";
}
}
void maxx(){
int head=1;
int tail=2;
for(int i=1;i<=n;i++){
while(Q[head]<=i-k)
head++;
while(head<=(tail-1)&&a[Q[tail-1]]<a[i]){
tail--;
}
Q[tail]=i;
tail++;
if(i>=k)
cout<<a[Q[head]]<<" ";
}
}
int main(){
//freopen("c.in","r",stdin);
cin>>n;
cin>>k;
for(int i=1;i<=n;i++){
cin>>a[i];
}
minn();
cout<<endl;
maxx();
return 0;
}
by bovine__kebi @ 2020-05-01 19:51:59
数组开大一点点试试?
by Suuon_Kanderu @ 2020-05-30 21:43:50
2e6