#P13997. 【MX-X19-T6】「FeOI Round 4.5」はぐ

【MX-X19-T6】「FeOI Round 4.5」はぐ

Description

The overall time limit for this problem is long, and submitting too many times may trigger the daily submission limit on Luogu. Please plan your submissions accordingly.

Shizuku gives you a tree with nn nodes, numbered 1n1 \sim n. The ii-th node has a weight aia_i.

She asks you qq queries. Each query provides two nodes x,yx, y. Let pip_i be the ii-th node on the path from xx to yy (indexing starts from 00). You need to compute:

$$\bigoplus_{i = 0}^{\mathrm{dis}(x, y)} (a_{p_i} + i)$$

Here, dis(x,y)\mathrm{dis}(x, y) is the number of edges on the path from xx to yy, and \oplus denotes the bitwise XOR operation.

Input Format

The first line contains two positive integers n,qn, q.

The second line contains nn non-negative integers a1,,ana_1, \ldots, a_n.

The next n1n - 1 lines each contain two positive integers u,vu, v, indicating an edge between uu and vv in the tree.

The next qq lines each contain two positive integers x,yx, y, representing a query.

Output Format

Output qq lines. The ii-th line should contain a non-negative integer, which is the answer to the ii-th query.

5 2
2 4 0 5 1
1 2
1 3
2 4
2 5
3 4
1 5
13
4
10 10
1 1 4 5 1 4 1 0 2 4
3 1
4 9
1 5
1 10
10 8
7 4
1 7
6 7
8 2
1 2
1 3
8 9
6 2
4 10
5 2
7 9
7 4
4 10
9 5
2
4
12
0
3
3
3
7
3
6

Hint

【Sample Explanation #1】

For the first query in sample one, p=(3,1,2,4)p = (3, 1, 2, 4). The answer is $(a_3 + 0) \oplus (a_1 + 1) \oplus (a_2 + 2) \oplus (a_4 + 3) = 0 \oplus 3 \oplus 6 \oplus 8 = 13$.

For the second query in sample one, p=(1,2,5)p = (1, 2, 5). The answer is $(a_1 + 0) \oplus (a_2 + 1) \oplus (a_5 + 2) = 2 \oplus 5 \oplus 3 = 4$.

【Data Range】

This problem uses bundled testing.

Subtask ID n,qn,q \leq Special Properties Score
11 10310^3 None 77
22 5×1045 \times 10^4 ai=0a_i=0 99
33 aia_i is a multiple of 2122^{12} 1717
44 The tree is randomly generated^\dagger 55
55 2×1052 \times 10^5 The tree is a chain 1616
66 5×1045 \times 10^4 None 1919
77 2×1052 \times 10^5 2727

\dagger: The random generation method: for each uu from 22 to nn, uniformly randomly select an integer vv from [1,u1][1, u - 1], and add an edge between uu and vv. Finally, the node labels are randomly shuffled.

For all test cases, 1n,q2×1051 \le n,q \le 2 \times 10^5, 1x,yn1 \le x, y \le n, 0ain0 \le a_i \le n. The given edges are guaranteed to form a tree.

Translated by DeepSeek V3.1