LUOGU 1440

#include<cstdio>
#include<algorithm>
#include<cstring>
#define N 1000005
using namespace std;
int q[N],a[N],n,m,l,r=-1;
int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]);
    q[++r]=1;
    for (int i=1;i<=n;i++)
    {
        while (q[l]<=i-m && r>=l) l++;
        while (a[q[r]]>a[i] && r>=l) r--;
        q[++r]=i;
        printf("%d\n",a[q[l]]);
    }
     return 0;
}
/*
5 2
2 4 1 5 7
8 3
2 0 0 2 0 6 2 1
8 1
2 0 0 1 0 7 0 3
*/

 

posted @ 2018-01-30 20:37  MSPqwq  阅读(139)  评论(0编辑  收藏  举报