#P4592. [TJOI2018] 异或
[TJOI2018] 异或
Description
There is a tree with nodes, rooted at , with nodes numbered from to . Each node has a value . There are operations as follows:
- : Query the maximum value of among nodes in the subtree of node .
- : Query the maximum value of among nodes on the simple path from node to node .
Input Format
The first line contains two integers and , representing the number of nodes and the number of queries.
The second line contains integers, where the -th integer is the value of node .
Each of the next lines contains two integers , indicating that there is an edge connecting and .
Each of the next lines starts with an integer , indicating the type of operation.
- If , then it is followed by two integers , representing a query for the maximum value of among nodes in the subtree of node .
- If , then it is followed by three integers , representing a query for the maximum value of among nodes on the simple path from node to node .
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 of the testdata, .
- For of the testdata, .
- For of the testdata, .
- For of the testdata, , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号