Floating__Dream @ 2018-08-01 15:46:25
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
using namespace std;
int l,r,n,k,a[100050],q[1000005];
int main(){
cin>>n>>k;
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
l=r=1;
for(int i=1;i<=n;i++)
{
while(l<r&&a[q[r-1]]>a[i])
r--;
q[r++]=i;
while(l<r&&q[l]<=i-k)
l++;
if(i>=k)
printf("%d ",a[q[l]]);
}
cout<<endl;
memset(q,0,sizeof(q));
l=r=1;
for(int i=1;i<=n;i++)
{
while(l<r&&a[q[r-1]]<a[i])
r--;
q[r++]=i;
while(l<r&&q[l]<=i-k)
l++;
if(i>=k)
printf("%d ",a[q[l]]);
}
}
by 八声甘州 @ 2018-08-01 16:05:34
100%的数据,n<=10^6
我就是这么错的