#P15044. [UOI 2022 II Stage] 树

    ID: 16972 远端评测题 5000ms 512MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>线段树2022线性基UOI(乌克兰)

[UOI 2022 II Stage] 树

Problem Description

Xsonia has a rooted tree with root vertex 11 and nn vertices. Each vertex has a number written on it. The number written on vertex ii is aia_i.

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 vv are all vertices on the path from vv to the root (excluding vv itself). The subtree of a vertex vv is the set of all vertices that have vv as an ancestor, including vv itself.

The XOR sum of a set S=(u1,u2,u3,…,uk)S = (u_1, u_2, u_3, \dots, u_k) is defined as u1⊕u2⊕u3⊕⋯⊕uku_1 \oplus u_2 \oplus u_3 \oplus \dots \oplus u_k, where ⊕\oplus is the bitwise XOR operation, written as xor in Pascal, and as ^ in C++/Java/Python.

For a set of numbers SS, consider the set of XOR sums of all its possible subsets. Call this set F(S)F(S).

Xsonia’s friends keep asking her questions like this: “If we consider the multiset of all numbers in the subtree of vertex vv (denoted as UvU_v), what is the kk-th smallest number in the set F(Uv)F(U_v)?” In other words, if we take all numbers in the subtree of vertex vv and consider the XOR sums of all their subsets, what is the kk-th smallest number in the resulting set? If such a number does not exist (i.e., k>∣F(Uv)∣k > |F(U_v)|), then Xsonia answers −1-1. Note that F(Uv)F(U_v) 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 n,gn, g (2≤n≤5⋅1042 \leq n \leq 5 \cdot 10^4, 0≤g≤70 \leq g \leq 7), representing the number of vertices in the tree and the test group ID, respectively.

The next n−1n - 1 lines each contain two integers xi,yix_i, y_i (1≤xi,yi≤n1 \leq x_i, y_i \leq n), indicating that there is an edge between vertices xix_i and yiy_i. It is guaranteed that the graph is a tree.

The next line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (0≤ai<2200 \leq a_i < 2^{20}), representing the initial array aa of numbers on the vertices.

The next line contains an integer qq (1≤q≤5⋅1041 \leq q \leq 5 \cdot 10^4), representing the number of queries.

Each of the next qq lines describes one query.

A query that modifies a number has the format 1 xi yi1 \ x_i \ y_i (1≤xi≤n1 \leq x_i \leq n, 0≤yi<2200 \leq y_i < 2^{20}). This means the number on vertex xix_i becomes yiy_i.

The other type of query has the format 2 vi ki2 \ v_i \ k_i (1≤vi≤n1 \leq v_i \leq n, 1≤ki≤1091 \leq k_i \leq 10^9). This query asks for the kik_i-th smallest number in the set F(Uvi)F(U_{v_i}), where UviU_{v_i} is the set of numbers in the subtree of vertex viv_i, and F(Uvi)F(U_{v_i}) is the set of XOR sums of all its subsets. If ki>∣F(Uvi)∣k_i > |F(U_{v_i})|, output −1-1.

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 aia_i.

:::align{center} :::

In the first query, consider the subtree of vertex 22. It contains the numbers 1,2,31, 2, 3.

F([1,2,3])=[0,1,2,3]F([1,2,3]) = [0, 1, 2, 3].

In the second query, consider the whole subtree. F([1,2,3,4])=[0,1,2,3,4,5,6,7]F([1, 2, 3, 4]) = [0,1,2,3,4,5,6,7].

After modifying one number, the tree becomes:

:::align{center} :::

Now, the subtree of vertex 22 contains the numbers 1,2,41, 2, 4.

F([1,2,4])=[0,1,2,3,4,5,6,7]F([1,2,4]) = [0,1,2,3,4,5,6,7].

Scoring

  • (6 points): q,n≤15q, n \leq 15.
  • (16 points): q,n≤500q, n \leq 500.
  • (18 points): q,n≤2000q, n \leq 2000.
  • (7 points): In all second-type queries, vi=1v_i = 1.
  • (13 points): There are no modification queries.
  • (11 points): All ai,yia_i, y_i are powers of 22.
  • (29 points): No additional constraints.

Translated by DeepSeek V3.

Translated by ChatGPT 5