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 72 73 74 75 76 77
| #include<bits/stdc++.h> #define lowbit(x) (x & (-x))
using namespace std;
const int MAXN = 100005;
int n, m;
int edgeCount; int head[MAXN], toNode[MAXN << 1], nextEdge[MAXN << 1];
int countDfn, dfn[MAXN], siz[MAXN], val[MAXN];
int bit[MAXN];
inline void addEdge(int from, int to) { edgeCount++; toNode[edgeCount] = to; nextEdge[edgeCount] = head[from]; head[from] = edgeCount; return; }
inline void changeBit(int pos, int val) { for (int i = pos; i <= n; i += lowbit(i)) bit[i] ^= val; return; } inline int queryBit(int l, int r) { int res1 = 0, res2 = 0; for (int i = l - 1; i; i -= lowbit(i)) res1 ^= bit[i]; for (int i = r; i; i -= lowbit(i)) res2 ^= bit[i]; return res1 ^ res2; }
inline void dfs(int from, int father) { siz[from]++; countDfn++; dfn[from] = countDfn; for (int i = head[from]; i; i = nextEdge[i]) { int to = toNode[i]; if (to != father) { dfs(to, from); siz[from] += siz[to]; } } return; }
int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) scanf("%d", &val[i]); for (int i = 1; i < n; ++i) { int from, to; scanf("%d%d", &from, &to); addEdge(from, to), addEdge(to, from); } dfs(1, 0); for (int i = 1; i <= n; ++i) changeBit(dfn[i], val[i]); while (m--) { int opt, pos, curVal; scanf("%d%d", &opt, &pos); if (opt == 1) { scanf("%d", &curVal); changeBit(dfn[pos], val[pos]); changeBit(dfn[pos], curVal); val[pos] = curVal; } else cout << queryBit(dfn[pos], dfn[pos] + siz[pos] - 1) << '\n'; } return 0; }
|