徐振轩2011 @ 2024-08-13 19:51:59
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 * 4 + 100;
int n,k,x,y;
int a[maxn],mins[maxn];
void build (int o,int l,int r){
if (l == r) {
mins[o] = a[l];
}else{
int mid = l + (r - l) / 2;
build (o * 2,l,mid);
build (o * 2 + 1,mid + 1,r);
mins[o] = min(mins[o * 2],mins[o * 2 + 1]);
}
}
int query (int o,int l,int r){
if (x <= l && r <= y) return mins[o];
int sans = INT_MAX;
int mid = l + (r - l) / 2;
if (x <= mid) sans = min(sans,query (o * 2,l,mid));
if (y > mid) sans = min(sans,query (o * 2 + 1,mid + 1,r));
return sans;
}
int main(){
cin >> n >> k;
for (int i = 1 ; i <= n ; i++) scanf ("%d",&a[i]);
build (1,1,n);
cout << 0 << endl;
for (int i = 2 ; i <= n ; i++){
x = max(1,i - k);
y = i - 1;
cout << query(1,1,n) << endl;
}
return 0;
}
喜获
by YangTL @ 2024-08-13 19:54:46
qp