#P3690. 【模板】动态树(LCT)

    ID: 2688 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>O2优化动态树树链剖分,树剖Link-Cut Tree,LCT

【模板】动态树(LCT)

Description

Given nn nodes and each node’s weight, you need to process the next mm operations.
There are four types of operations, numbered from 00 to 33. Nodes are numbered from 11 to nn.

  • 0 x y asks for the xor\text{xor} sum of the weights of the nodes on the path from xx to yy. It is guaranteed that xx and yy are connected.
  • 1 x y connects xx to yy. If xx and yy are already connected, do nothing.
  • 2 x y deletes the edge (x,y)(x, y). The existence of edge (x,y)(x, y) is not guaranteed.
  • 3 x y sets the weight of node xx to yy.

Input Format

The first line contains two integers nn and mm, representing the number of nodes and the number of operations.

The next nn lines each contain one integer. On the (i+1)(i + 1)-th line, the integer aia_i denotes the weight of node ii.

The next mm lines each contain three integers, representing the operation type and its parameters.

Output Format

For each operation of type 00, output one line with one integer, the xor\text{xor} sum of the node weights on the path from xx to yy.

3 3 
1
2
3
1 1 2
0 1 2 
0 1 1
3
1

5 14
114
514
19
19
810
1 1 2
0 1 2
2 1 2
1 1 2
1 2 3
2 1 3
1 1 3
1 4 5
1 2 5
0 3 5
0 3 4
3 5 233333
0 1 5
0 2 5

624
315
296
232709
232823

Hint

Constraints and Conventions

For all testdata, it is guaranteed that:

  • 1n1051 \leq n \leq 10^5, 1m3×1051 \leq m \leq 3 \times 10^5, 1ai1091 \leq a_i \leq 10^9.
  • For operations 0,1,20, 1, 2, it holds that 1x,yn1 \leq x, y \leq n.
  • For operation 33, it holds that 1xn1 \leq x \leq n, 1y1091 \leq y \leq 10^9.

Translated by ChatGPT 5