#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 nodes, numbered . The -th node has a weight .
She asks you queries. Each query provides two nodes . Let be the -th node on the path from to (indexing starts from ). You need to compute:
$$\bigoplus_{i = 0}^{\mathrm{dis}(x, y)} (a_{p_i} + i)$$Here, is the number of edges on the path from to , and denotes the bitwise XOR operation.
Input Format
The first line contains two positive integers .
The second line contains non-negative integers .
The next lines each contain two positive integers , indicating an edge between and in the tree.
The next lines each contain two positive integers , representing a query.
Output Format
Output lines. The -th line should contain a non-negative integer, which is the answer to the -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, . 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, . 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 | Special Properties | Score | |
|---|---|---|---|
| None | |||
| is a multiple of | |||
| The tree is randomly generated | |||
| The tree is a chain | |||
| None | |||
: The random generation method: for each from to , uniformly randomly select an integer from , and add an edge between and . Finally, the node labels are randomly shuffled.
For all test cases, , , . The given edges are guaranteed to form a tree.
Translated by DeepSeek V3.1
京公网安备 11011102002149号