#P16451. rvtmpq
rvtmpq
Problem Description
Given a tree with nodes, each node has two weights . Define as the smallest connected subgraph that contains the node set . Then there are operations, each of the following forms:
- Operation 1: Given , let be the set formed by all numbers in . For all , add to .
- Operation 2: Given , query the value of .
- Operation 3: Given , query the sum of values of all nodes on the path from to .
All answers are taken modulo .
The problem is strictly online.
Input Format
The first line contains two integers , representing the size of the tree and the number of operations.
The second line contains integers, representing the array .
The third line contains integers, representing the array .
The next lines each contain two integers , representing an edge of the tree.
The next lines each start with an integer . If , then three integers follow, representing Operation 1. If , then one integer follows, representing Operation 2. If , then one integer follows, representing Operation 3.
You need to XOR in Operation 1, in Operation 2, and in Operation 3 with the answer of the previous query operation . In particular, if there is no query operation before this operation, then .
Output Format
For each Operation 2 and Operation 3, output one line with the result modulo .
4 5
2 3 4 5
5 3 2 1
3 1
3 2
2 4
2 4
1 6 1 4
2 4
1 3 6 2
3 3
5
2
2
Hint
Constraints: for of the testdata, , , and .
It is guaranteed that after decryption, satisfy , , and .
Let be the number of operations with , be the number of operations with , and be the number of operations with . It is guaranteed that .
Translated by ChatGPT 5