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 71
| #include <cstdio> #define lc p<<1, s, mid #define rc p<<1|1, mid+1, e #define mid ((s+e)>>1)
using namespace std; const int N = 2e5 + 5; int tot[N * 4], ans[N];
int pos[N], val[N];
void pushup(int p) { tot[p] = tot[p << 1] + tot[p << 1 | 1]; }
void build(int p, int s, int e) { if(s == e) { tot[p] = 1; return; } build(lc); build(rc); pushup(p); }
void update(int p, int s, int e, int i) { if(s == e) { tot[p] = 0; ans[e] = val[i]; return; } if(tot[p << 1] > pos[i]) update(lc, i); else { pos[i] -= tot[p << 1]; update(rc, i); } pushup(p); }
int main() { int n; while(~scanf("%d", &n)) { build(1, 1, n); for(int i = 1; i <= n; ++i) scanf("%d%d", &pos[i], &val[i]);
for(int i = n; i > 0; --i) update(1, 1, n, i);
for(int i = 1; i < n; ++i) printf("%d ", ans[i]);
printf("%d\n", ans[n]); }
return 0; }
|