#P16451. rvtmpq

rvtmpq

Problem Description

Given a tree with nn nodes, each node has two weights ai,bia_i, b_i. Define f(S)f(S) as the smallest connected subgraph that contains the node set SS. Then there are qq operations, each of the following forms:

  • Operation 1: Given l,r,vl, r, v, let SS be the set formed by all numbers in [l,r][l, r]. For all i∈f(S)i \in f(S), add v×biv \times b_i to aia_i.
  • Operation 2: Given xx, query the value of axa_x.
  • Operation 3: Given xx, query the sum of aa values of all nodes on the path from 11 to xx.

All answers are taken modulo 2322^{32}.

The problem is strictly online.

Input Format

The first line contains two integers n,qn, q, representing the size of the tree and the number of operations.

The second line contains nn integers, representing the array aa.

The third line contains nn integers, representing the array bb.

The next n−1n - 1 lines each contain two integers x,yx, y, representing an edge of the tree.

The next qq lines each start with an integer opop. If op=1op = 1, then three integers l,r,vl, r, v follow, representing Operation 1. If op=2op = 2, then one integer xx follows, representing Operation 2. If op=3op = 3, then one integer xx follows, representing Operation 3.

You need to XOR l,r,vl, r, v in Operation 1, xx in Operation 2, and xx in Operation 3 with the answer of the previous query operation lasanslasans. In particular, if there is no query operation before this operation, then lasans=0lasans = 0.

Output Format

For each Operation 2 and Operation 3, output one line with the result modulo 2322^{32}.

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 100%100\% of the testdata, 1≤n≤8×1051 \le n \le 8 \times 10^5, 1≤q≤3×1051 \le q \le 3 \times 10^5, and 0≤l,r,v,x,ai,bi<2320 \le l, r, v, x, a_i, b_i < 2^{32}.

It is guaranteed that after decryption, l,r,v,xl, r, v, x satisfy 1≤l≤r≤n1 \le l \le r \le n, 0≤v<2320 \le v < 2^{32}, and 1≤x≤n1 \le x \le n.

Let cnt1cnt_1 be the number of operations with op=1op = 1, cnt2cnt_2 be the number of operations with op=2op = 2, and cnt3cnt_3 be the number of operations with op=3op = 3. It is guaranteed that max⁡(cnt1,cnt2,cnt3)≤0.6q\max(cnt_1, cnt_2, cnt_3) \le 0.6q.

Translated by ChatGPT 5