#P6018. [Ynoi2010] Fusion tree

    ID: 6175 远端评测题 2000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>树形数据结构2010O2优化字典树 TrieYnoi

[Ynoi2010] Fusion tree

Problem Description

There is a big tree in a magic forest, and children often hold gatherings under it.

The tree can be seen as an undirected connected graph with nn nodes and n1n - 1 edges. Each node of the tree has some bottles of mineral water. Initially, node ii has aia_i bottles.

Majies lives at the top of the tree. One day, he wants to remodel the tree so that it will be convenient for him to sort the empty mineral water bottles for recycling after he drinks a lot of water.

Majies likes binary operations, so he will perform the following three types of operations:

  1. Add 11 to the number of mineral water bottles on every node whose distance to a node xx is 11. The distance between two nodes on the tree is defined as the number of edges on the shortest path between them.
  2. Drink vv bottles of water at node xx.
  3. Query the xor sum of the numbers of mineral water bottles on all nodes whose distance to a node xx is 11.

Majies has mm operations in total. You need to output the answer after each operation of type 33.

Input Format

The first line contains two positive integers n,mn, m, which represent the number of nodes in the tree and the number of queries.

Lines 22 to nn each contain two integers, indicating an edge connecting these two nodes.

Line n+1n + 1 contains nn integers. The ii-th integer indicates the initial number of mineral water bottles at node ii.

Lines n+2n + 2 to n+m+1n + m + 1 each start with an integer optopt representing the operation type.

If opt=1opt = 1 or opt=3opt = 3, then an integer xx follows, indicating the node that Majies operates on.

Otherwise, two integers x,vx, v follow, indicating the node that Majies operates on and the number of bottles he drinks.

Output Format

For each operation of type 33, output one line containing one integer, which is the answer.

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

Hint

Idea: dangxingyu, Solution: dangxingyu, Code: dangxingyu, Data: dangxingyu.

For 30%30\% of the testdata, n103n \le 10^3, m103m \le 10^3.

For 60%60\% of the testdata, n105n \le 10^5, m105m \le 10^5.

For another 10%10\% of the testdata, there exists a node such that the distance from every node to this node is 1\le 1.

For 100%100\% of the testdata, 1n5×1051 \le n \le 5\times 10^5, 1m5×1051 \le m \le 5\times 10^5, 0ai1050 \le a_i \le 10^5, 1xn1 \le x \le n, opt{1,2,3}opt\in\{1,2,3\}.

It is guaranteed that the number of mineral water bottles at each node is non-negative at any time.

Friendly reminder: mineral water bottles are neither dry waste nor wet waste; they are recyclable waste.

Translated by ChatGPT 5