输入的第一行包含两个正整数 N, M, 分别表示数组的长度和操作的个数。
第二行包含N个整数,依次为初始状态下数组各位的值(依次为 a_i,1≤i≤N)。
接下来M行每行包含3或4个整数,代表两种操作之一(ii为基于的历史版本号):
-
对于操作1,格式为v?i?? 1 loc?i?? value?i??,即为在版本v_iv?i??的基础上,将 a?loc?i???? 修改为 value?i??
- 对于操作2,格式为v?i?? 2 loc?i?? ,即访问版本 v?i?? 中的 a?loc?i???? 的值
5 10
59 46 14 87 41
0 2 1
0 1 1 14
0 1 1 57
0 1 1 88
4 2 4
0 2 5
0 2 4
4 2 1
2 2 2
1 1 5 91
1 //It is made by Awson on 2017.10.3
2 #include <set>
3 #include <map>
4 #include <cmath>
5 #include <ctime>
6 #include <queue>
7 #include <stack>
8 #include <vector>
9 #include <cstdio>
10 #include <string>
11 #include <cstring>
12 #include <cstdlib>
13 #include <iostream>
14 #include <algorithm>
15 #define LL long long
16 #define Max(a, b) ((a) > (b) ? (a) : (b))
17 #define Min(a, b) ((a) < (b) ? (a) : (b))
18 #define sqr(x) ((x)*(x))
19 #define insert INSERT
20 using namespace std;
21 const int N = 1e6;
22 void read(int &x) {
23 char ch; bool flag = 0;
24 for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == ‘-‘)) || 1); ch = getchar());
25 for (x = 0; isdigit(ch); x = (x<<1)+(x<<3)+ch-48, ch = getchar());
26 x *= 1-2*flag;
27 }
28
29 struct node {
30 int key;
31 node *child[2];
32 }sgm[N*20+5], *pos = sgm;
33 node* root[N+5];
34 int n, m, a[N+5];
35 int opt, v, loc, val;
36
37 void build(node *o, int l, int r) {
38 if (l == r) {
39 o->key = a[l];
40 return;
41 }
42 int mid = (l+r)>>1;
43 o->child[0] = ++pos; build(o->child[0], l, mid);
44 o->child[1] = ++pos; build(o->child[1], mid+1, r);
45 }
46 void insert(node* &o, int l, int r, int loc, int val) {
47 node* tmp = o;
48 o = ++pos;
49 if (l == r) {
50 o->key = val;
51 return;
52 }else {
53 o->child[0] = tmp->child[0];
54 o->child[1] = tmp->child[1];
55 }
56 int mid = (l+r)>>1;
57 if (loc <= mid) insert(o->child[0], l, mid, loc, val);
58 else insert(o->child[1], mid+1, r, loc, val);
59 }
60 int query(node *o, int l, int r, int loc) {
61 if (l == r) return o->key;
62 int mid = (l+r)>>1;
63 if (loc <= mid) return query(o->child[0], l, mid, loc);
64 else return query(o->child[1], mid+1, r, loc);
65 }
66 void work() {
67 read(n), read(m);
68 for (int i = 1; i <= n; i++) read(a[i]);
69 root[0] = pos;
70 build(root[0], 1, n);
71 for (int i = 1; i <= m; i++) {
72 read(v), read(opt);
73 if (opt == 1) {
74 read(loc), read(val);
75 root[i] = root[v];
76 insert(root[i], 1, n, loc, val);
77 }
78 else {
79 read(loc);
80 root[i] = root[v];
81 printf("%d\n", query(root[i], 1, n, loc));
82 }
83 }
84 }
85 int main() {
86 work();
87 return 0;
88 }