0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 20:56:37 +00:00

P1440 求m区间内的最小值

R52819535
This commit is contained in:
Baoshuo Ren 2021-07-11 10:13:16 +08:00 committed by Baoshuo Ren
parent 79558550a7
commit 34b426f6b0
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -0,0 +1,58 @@
#include <bits/stdc++.h>
using namespace std;
int n, m, a[2000005];
struct node {
int l, r, min;
node() {
l = r = 0;
min = 0x3f3f3f3f;
}
node(int _l, int _r) {
l = _l;
r = _r;
min = 0x3f3f3f3f;
}
} tr[2000005 << 2];
void pushup(int u) {
tr[u].min = min(tr[u << 1].min, tr[u << 1 | 1].min);
}
void build(int u, int l, int r) {
tr[u] = node(l, r);
if (l == r) {
tr[u].min = a[l];
return;
}
int mid = l + r >> 1;
build(u << 1, l, mid);
build(u << 1 | 1, mid + 1, r);
pushup(u);
}
int query(int u, int l, int r) {
if (l <= tr[u].l && tr[u].r <= r) {
return tr[u].min;
}
int mid = tr[u].l + tr[u].r >> 1;
int s = 0x3f3f3f3f;
if (l <= mid) s = min(s, query(u << 1, l, r));
if (r > mid) s = min(s, query(u << 1 | 1, l, r));
return s;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
}
build(1, 1, n);
for (int i = 1; i <= n; i++) {
printf("%d\n", (max(i - m, 1) > i - 1 ? 0 : query(1, max(i - m, 1), i - 1)));
}
return 0;
}