#P15044. [UOI 2022 II Stage] 树
[UOI 2022 II Stage] 树
Problem Description
Xsonia has a rooted tree with root vertex and vertices. Each vertex has a number written on it. The number written on vertex is .
Recall that a tree is a connected graph with no cycles. A rooted tree means choosing one vertex in the tree as the root.
In a rooted tree, the ancestors of a vertex are all vertices on the path from to the root (excluding itself). The subtree of a vertex is the set of all vertices that have as an ancestor, including itself.
The XOR sum of a set is defined as , where is the bitwise XOR operation, written as xor in Pascal, and as ^ in C++/Java/Python.
For a set of numbers , consider the set of XOR sums of all its possible subsets. Call this set .
Xsonia’s friends keep asking her questions like this: “If we consider the multiset of all numbers in the subtree of vertex (denoted as ), what is the -th smallest number in the set ?” In other words, if we take all numbers in the subtree of vertex and consider the XOR sums of all their subsets, what is the -th smallest number in the resulting set? If such a number does not exist (i.e., ), then Xsonia answers . Note that is a set, not a multiset. That is, even if a number appears multiple times, it is counted only once.
In addition, Xsonia’s friends sometimes ask her to modify a number on the tree.
Input Format
The first line contains two integers (, ), representing the number of vertices in the tree and the test group ID, respectively.
The next lines each contain two integers (), indicating that there is an edge between vertices and . It is guaranteed that the graph is a tree.
The next line contains integers (), representing the initial array of numbers on the vertices.
The next line contains an integer (), representing the number of queries.
Each of the next lines describes one query.
A query that modifies a number has the format (, ). This means the number on vertex becomes .
The other type of query has the format (, ). This query asks for the -th smallest number in the set , where is the set of numbers in the subtree of vertex , and is the set of XOR sums of all its subsets. If , output .
Output Format
For each query of the second type, output the answer on a separate line.
5 0
1 2
1 5
2 3
2 4
4 2 3 1 2
7
2 2 4
2 1 2
2 2 3
1 3 4
2 5 1
2 2 8
2 1 5
3
1
2
0
7
4
Hint
Sample Explanation
Explanation for the first sample. The number next to each vertex is .
:::align{center}
:::
In the first query, consider the subtree of vertex . It contains the numbers .
.
In the second query, consider the whole subtree. .
After modifying one number, the tree becomes:
:::align{center}
:::
Now, the subtree of vertex contains the numbers .
.
Scoring
- (6 points): .
- (16 points): .
- (18 points): .
- (7 points): In all second-type queries, .
- (13 points): There are no modification queries.
- (11 points): All are powers of .
- (29 points): No additional constraints.
Translated by DeepSeek V3.
Translated by ChatGPT 5