-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathP1440.c
More file actions
44 lines (37 loc) · 738 Bytes
/
P1440.c
File metadata and controls
44 lines (37 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "stdio.h"
#include "stdlib.h"
#define N 2000006
struct node {
int idx, val;
} s[N];
int head, tail;
static void init() {
head = 0, tail = -1;
}
static void expire(int idx) {
if (head <= tail && s[head].idx < idx) head++;
}
static void add(int idx, int val) {
while (head <= tail && s[tail].val > val) tail--;
tail++;
s[tail].idx = idx;
s[tail].val = val;
}
static int get() {
return s[head].val;
}
int main() {
init();
int n, m, val, pre;
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d", &val);
if (i) {
expire(i - m);
add(i - 1, pre);
}
printf("%d\n", get());
pre = val;
}
exit(0);
}