luogu#P5127. 子异和

子异和

Problem Description

Xiao L and Xiao K are having a heated discussion.

(You do not need to know who said which line...)

“Do you know non-empty subsets?”

“Of course! For example, for the set {1,2,3}\{1,2,3\}, all of its non-empty subsets are $\{1\},\{2\},\{3\},\{1,2\},\{2,3\},\{1,3\},\{1,2,3\}$.”

“Then do you know the XOR sum of the numbers in each non-empty subset?”

“I do! It is just 1,2,3,12=3,23=1,13=2,123=01,2,3,1⊕2=3,2⊕3=1,1⊕3=2,1⊕2⊕3=0.”

“Then do you know what their total sum is? We call it the subset XOR sum.”

“Subset XOR sum... what a strange name, but I know it is 1+2+3+3+1+2+0=121+2+3+3+1+2+0=12.”

“Then let me ask you, what is the subset XOR sum of {a1,a2,...,an}\{a_1,a_2,...,a_n\}?”

“Just brute force it slowly!”

“What if n200000n\le 200000?”

“...”

“What if we put the problem on a tree?”

“... Can you solve it then?”

“Of course... I cannot...”

Now only you can help Xiao L and Xiao K. Please solve this problem.

To express the statement more clearly, we explain it again.

There is a tree with nn nodes, and there are mm operations in total. These operations are given in order. Each operation is either a query or a modification.

Each query operation gives two node indices a,ba,b. As is well known, there is a unique path between aa and bb on the tree. Let the multiset of node weights of all nodes on this path be SS. You need to output the subset XOR sum of SS. The answer is taken mod (109+7)mod\space(10^9+7).

Each modification operation gives two node indices a,ba,b and an integer value cc. You need to XOR the weight of every node on the unique path from node aa to node bb by cc.

Here, “set” means multiset.

Input Format

The first line contains three positive integers n,mn,m.

The next n1n-1 lines each contain two positive integers a,ba,b, meaning there is an edge between node aa and node bb. There will be no multiple edges or self-loops.

The next line contains nn non-negative integers. The ii-th non-negative integer is the initial weight of node ii.

The next mm lines each contain several integers describing an operation. The first integer of each line is either 11 or 22. If it is 11, then this operation is a query, and the next two numbers are a,ba,b; if it is 22, then this operation is a modification, and the next three numbers are a,b,ca,b,c.

Output Format

For each query, output one line containing the answer.

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

Hint

Sample explanation:

For the first query, the path from 11 to 11 passes through node 11, the multiset of node weights is {1}\{1\}, and the subset XOR sum is 11.

After two modifications, the weight of node 11 is 00, and the weight of node 33 is 11.

For the second query, the multiset of node weights on the path from 11 to 33 is {0,1}\{0,1\}, and the subset XOR sum is 0+1+1=20+1+1=2.

This problem has 1010 test points. Each test point is worth 1010 points, for a total of 100100 points.

Test point ID Range of nn Range of mm Special property
121-2 1n10001\le n\le 1000 1m10001\le m\le 1000 None
353-5 1n2000001\le n\le 200000 1m2000001\le m\le 200000 The indices of the two nodes connected by each edge are adjacent
6106-10 None

Constraints:

For 100%100\% of the data, all input numbers are non-negative integers not greater than 109+710^9+7, and 1a,bn1\le a,b\le n.

Translated by ChatGPT 5