#P7446. [Ynoi2007] rfplca

[Ynoi2007] rfplca

Problem Description

Given a rooted tree of size nn with node 11 as the root. The tree is given in the following way: you are given a2,a3,,ana_2,a_3,\dots,a_n, and it is guaranteed that 1ai<i1\leq a_i<i. Add an edge between aia_i and ii to form a tree.

Then there are mm operations of two types:

  • 1 l r x Set ai=max(aix,1)a_i=\max(a_i-x,1) for all lirl\leq i\leq r.
  • 2 u v Query the LCA of uu and vv in the tree formed by the current array aa.

Input Format

The first line contains two integers nn and mm.

The next line contains n1n-1 integers, representing a2,,ana_2,\dots,a_n.

Then follow mm lines, each containing three or four integers, representing one operation.

This problem is forced online. All inputs l,r,x,u,vl,r,x,u,v must be XORed with lastanslastans, where lastanslastans is defined as the answer of the previous query operation. If there has been no query operation before, then it is 00.

Output Format

For each operation of type 22, output one line with one integer as the answer.

6 4
1 2 3 3 4
2 3 4
1 1 0 2
2 6 5
2 1 0

3
3
1

Hint

Idea: Ynoi, Solution: Ynoi, Code: Ynoi, Data: Ynoi&nzhtl1477

For 100%100\% of the testdata, it holds that 2n,m4×1052\leq n,m\leq 4\times 10^5, 2lrn2\leq l\leq r\leq n, 1x4×1051\leq x\leq 4\times 10^5, 1u,vn1\leq u,v\leq n.

Translated by ChatGPT 5