https://www.luogu.org/problemnew/show/P2251
#include <iostream>
#include<algorithm>
#include<cstdlib>
#include <cstdio>
#include <cmath>
#include <cstring>
#define MAXN 1000005
using namespace std;
int f[MAXN][25],n,m;
void build()
{
for(int j = 1;j <= 20;++j){
for(int i = 1;i <= n;++i)
if(i+(1<<j)-1<=n)
f[i][j]=min(f[i][j-1],f[i+(1<<(j-1))][j-1]);
}
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&f[i][0]);
build();
for(int i=1;i<=n-m+1;++i){
int k=log2(m);
printf("%d\n",min(f[i][k],f[i+m-1-(1<<k)+1][k]));
}
return 0;
}