#P6053. [RC-02] XOR

[RC-02] XOR

Description

Note: In this problem, every \sum means taking the XOR-sum.

There is a rooted tree with nn nodes and n1n-1 edges. Initially, node 11 is the root.

Each node ii on the tree has a node value ViV_{i}.

Define the function $\operatorname{Xor}(x)=\sum_{y\in \operatorname{Subtree}(x)}{V_{y}}$, where Subtree(x)\operatorname{Subtree}(x) denotes the subtree of xx.

You need to support the following five operations:

  1. 1 x: Make xx the root, and query i=1nXor(i)\sum_{i=1}^{n}{\operatorname{Xor}(i)}.
  2. 2 x y: Set Vx=yV_{x}=y.
  3. 3 x y: Query LCA(x,y)\operatorname{LCA}(x,y).
  4. 4 x y: Query the XOR-sum of node values along the path from xx to yy.
  5. 5 x: Query Xor(x)\operatorname{Xor}(x).

Input Format

The first line contains three integers n,m,qn,m,q, representing the number of nodes, the number of operation type 11, and the number of the remaining operations.

The next line contains nn integers, representing V1VnV_{1}\dots V_{n}.

The next n1n-1 lines each contain two integers x,yx,y, indicating that there is an edge between xx and yy.

The next m+qm+q lines each contain two or three integers. The first number is the operation type, followed by the parameters of that operation.

Output Format

Output several lines, each being the result of operations 1,3,4,51,3,4,5.

5 4 4
0 0 2 2 1
1 2
1 3
2 4
2 5
1 1
1 1
1 1
2 3 0
4 3 3
5 1
1 2
3 1 2

3
3
3
0
3
0
2

10 8 8
5 6 2 1 0 4 0 0 0 3
1 2
1 3
2 4
2 5
3 6
3 7
4 8
4 9
5 10
3 10 9
2 1 6
1 5
1 4
1 7
1 7
5 1
1 1
3 1 5
1 7
1 9
2 5 0
4 9 6
1 10
4 10 7
5 1

2
3
3
3
3
2
3
1
3
7
7
7
1
0

Hint

For all testdata, it is guaranteed that 100n,m,q106100\le n,m,q\le 10^6, 0Vi23110\le V_i\le 2^{31}-1. The detailed Constraints are shown in the table below.

Test Point ID Time Limit / s nn mm qq
11 11 100 100 100 100 4×105 4 \times 10 ^ 5
2,32,3 10610^ { 6 }
4,54,5 104 10 ^ 4 100100
6,7,86,7,8 1 1 10610 ^ 6
99 1.8 1.8 106 10 ^ 6 100100 106 10^6
1010 2.3 2.3 106 10^6 106 10 ^ 6

Translated by ChatGPT 5