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 , 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 .”
“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 .”
“Then let me ask you, what is the subset XOR sum of ?”
“Just brute force it slowly!”
“What if ?”
“...”
“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 nodes, and there are 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 . As is well known, there is a unique path between and on the tree. Let the multiset of node weights of all nodes on this path be . You need to output the subset XOR sum of . The answer is taken .
Each modification operation gives two node indices and an integer value . You need to XOR the weight of every node on the unique path from node to node by .
Here, “set” means multiset.
Input Format
The first line contains three positive integers .
The next lines each contain two positive integers , meaning there is an edge between node and node . There will be no multiple edges or self-loops.
The next line contains non-negative integers. The -th non-negative integer is the initial weight of node .
The next lines each contain several integers describing an operation. The first integer of each line is either or . If it is , then this operation is a query, and the next two numbers are ; if it is , then this operation is a modification, and the next three numbers are .
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 to passes through node , the multiset of node weights is , and the subset XOR sum is .
After two modifications, the weight of node is , and the weight of node is .
For the second query, the multiset of node weights on the path from to is , and the subset XOR sum is .
This problem has test points. Each test point is worth points, for a total of points.
| Test point ID | Range of | Range of | Special property |
|---|---|---|---|
| None | |||
| The indices of the two nodes connected by each edge are adjacent | |||
| None |
Constraints:
For of the data, all input numbers are non-negative integers not greater than , and .
Translated by ChatGPT 5