#P5352. Terrible Homework
Terrible Homework
Description
Student hates doing homework the most.
Now, the teacher has assigned homework tasks to . Each task has a difficulty value .
At the beginning, every homework task is independent. There are some operations: each time, you add an edge between two tasks or delete an edge.
Because the teacher’s mood changes often, there are also operations that apply with a value to the difficulty values of all tasks on the path between two tasks .
Also, to satisfy ’s curiosity, you need to answer, for all tasks on the path between , the bitwise sum, bitwise sum, bitwise sum, and the ordinary sum of difficulty values.
Input Format
The first line contains two positive integers , representing the number of homework tasks and the number of operations.
The next line contains non-negative integers , representing the difficulty value of each task.
Then follow lines, each describing one operation:
- : Add an edge between tasks and . (It is guaranteed that no cycle will be formed, i.e. the graph is always a forest.)
- : Delete the edge between and . (It is guaranteed that this edge exists and will not be deleted more than once.)
- : Apply with to the difficulty values of all tasks on the path between and . (Including and , and it is guaranteed that they are connected; the same applies below.)
- : Query the bitwise sum of the difficulty values of all tasks on the path between and .
- : Query the bitwise sum of the difficulty values of all tasks on the path between and .
- : Query the bitwise sum of the difficulty values of all tasks on the path between and .
- : Query the ordinary sum of the difficulty values of all tasks on the path between and .
Output Format
For each operation, output the answer.
4 10
1 2 3 4
L 1 2
L 2 3
L 2 4
A 1 4
U 3 4 2
O 1 4
C 2 4
L 3 4
X 1 4
S 1 3
0
7
6
2
Hint
For of the testdata, .
For another of the testdata, .
For another of the testdata, .
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号