#P4592. [TJOI2018] 异或

    ID: 3531 远端评测题 3000ms 250MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>贪心2018各省省选可持久化进制天津

[TJOI2018] 异或

Description

There is a tree with nn nodes, rooted at 11, with nodes numbered from 11 to nn. Each node ii has a value viv_i. There are qq operations as follows:

  • 1 x z1~x~z: Query the maximum value of vzv \oplus z among nodes in the subtree of node xx.
  • 2 x y z2~x~y~z: Query the maximum value of vzv \oplus z among nodes on the simple path from node xx to node yy.

Input Format

The first line contains two integers nn and qq, representing the number of nodes and the number of queries.

The second line contains nn integers, where the ii-th integer is the value viv_i of node ii.

Each of the next n1n-1 lines contains two integers u,vu, v, indicating that there is an edge connecting uu and vv.

Each of the next qq lines starts with an integer opop, indicating the type of operation.

  • If op=1op = 1, then it is followed by two integers x,zx, z, representing a query for the maximum value of vzv \oplus z among nodes in the subtree of node xx.
  • If op=2op = 2, then it is followed by three integers x,y,zx, y, z, representing a query for the maximum value of vzv \oplus z among nodes on the simple path from node xx to node yy.

Output Format

For each query, output a single integer on one line representing the answer.

7 5
1 3 5 7 9 2 4
1 2
1 3
2 4
2 5
3 6
3 7
1 3 5
2 4 6 3
1 5 5
2 5 7 2
1 1 9
7
6
12
11
14

Hint

Constraints

  • For 10%10\% of the testdata, n,q102n, q \leq 10^2.
  • For 20%20\% of the testdata, n,q103n, q \leq 10^3.
  • For 40%40\% of the testdata, n,q104n, q \leq 10^4.
  • For 100%100\% of the testdata, 2n,q1052 \leq n, q \leq 10^5, 1u,v,x,yn1 \leq u, v, x, y \leq n, 1op21 \leq op \leq 2, 1vi,z<2301 \leq v_i, z \lt 2^{30}.

Translated by ChatGPT 5