-
Notifications
You must be signed in to change notification settings - Fork 0
/
2828.cpp
70 lines (57 loc) · 1.23 KB
/
2828.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<cstdio>
#include<cstring>
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define maxn 200005
int pos[maxn], val[maxn], spa[maxn << 2];
int ans[maxn];
void pushup(int rt){
spa[rt] = spa[rt << 1] + spa[rt << 1 | 1];
}
void build(int l, int r, int rt){
int m;
if(l == r){
spa[rt] = 1;
return;
}
m = (l + r) >> 1;
build(lson);
build(rson);
pushup(rt);
}
void update(int l, int r, int rt, int p, int v){
int m;
if(l == r){
spa[rt] = 0;
ans[l] = v;
return;
}
m = (l + r) >> 1;
if(p >= spa[rt << 1])
update(rson, p - spa[rt << 1], v);
else
update(lson, p, v);
pushup(rt);
}
int main(){
int i, N;
freopen("input.txt", "r", stdin);
while(scanf("%d", &N) == 1){
build(1, N, 1);
memset(val, -1, sizeof(val));
for(i = 0; i < N; i++){
scanf("%d%d", &pos[i], &val[i]);
}
for(i = N - 1; i >= 0; i--){
update(1, N, 1, pos[i], val[i]);
}
for(i = 1; i <= N; i++){
if(i != N){
printf("%d ", ans[i]);
}else{
printf("%d\n", ans[i]);
}
}
}
return 0;
}