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
| #include <cstdio> #include <algorithm> #include <vector> #include <iostream> #include <map> #include <queue> #include <cstring> #include <string> #include <cstdlib> #include <cmath> #include <set> using namespace std; const int inf = (1 << 30); typedef long long ll; const int maxn = 1e6 + 5; struct node { int ls, rs, w; } tr[maxn * 32]; int a[maxn], rt[maxn], cnt; void inser(int ver, int &now, int L, int R, int pos, int w) { now = ++cnt; tr[now] = tr[ver]; if (L == R) { tr[now].w = w; return; } int mid = L + R >> 1; if (mid >= pos) inser(tr[ver].ls, tr[now].ls, L, mid, pos, w); else inser(tr[ver].rs, tr[now].rs, mid + 1, R, pos, w); } int ask(int now, int L, int R, int pos) { if (L == R) return tr[now].w; int mid = L + R >> 1; if (mid >= pos) return ask(tr[now].ls, L, mid, pos); else return ask(tr[now].rs, mid + 1, R, pos); } int main() { int n, m, x; scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &x), inser(rt[0], rt[0], 1, n, i, x); for (int i = 1; i <= m; i++) { int ba, op, pos, w; scanf("%d %d", &ba, &op); if (op == 1) { scanf("%d %d", &pos, &w); inser(rt[ba], rt[i], 1, n, pos, w); } else { scanf("%d", &pos); int ans = ask(rt[ba], 1, n, pos); printf("%d\n", ans); rt[i] = rt[ba]; } } }
|