#P5537. 【XR-3】系统设计

    ID: 6285 远端评测题 2500ms 250MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>字符串线段树二分树状数组O2优化哈希 hashing

【XR-3】系统设计

Problem Description

Little X needs you to design a system.

This system first needs to read a rooted tree with nn nodes and a sequence aa of length mm, and then process qq operations.

There are two types of operations:

  1. 1 x l r means: set the starting point as node xx in the rooted tree, then traverse lrl \sim r in order. When traversing to ii, move from the current node to its aia_i-th smallest child (by node index). If at some moment the current node has fewer than aia_i children, or you have already finished traversing lrl \sim r, then stop at this node, output its index, and stop traversing.
  2. 2 t k means: modify the tt-th number in the sequence, changing ata_t to kk.

Input Format

The first line contains 33 positive integers n,m,qn, m, q, representing the number of nodes in the tree, the length of the sequence, and the number of operations.

The second line contains nn integers f1nf_{1 \dots n}, where fif_i is the index of the parent of node ii in the tree. In particular, let the root be rtrt, then frt=0f_{rt} = 0.

The third line contains mm positive integers a1ma_{1 \dots m}, representing the sequence aa.

Then follow qq lines, each describing one operation.

Constraints:

  • 1n,m,q5×1051 \le n, m, q \le 5 \times 10 ^ 5.
  • 1ain1 \le a_i \le n.
  • For operation type 11, it is guaranteed that 1xn1 \le x \le n, 1lrm1 \le l \le r \le m.
  • For operation type 22, it is guaranteed that 1tm1 \le t \le m, 1kn1 \le k \le n.

Output Format

For each operation of type 11, output one positive integer per line, representing the answer.

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

4
5
6
4
3
3
4
6

Hint

The input and output size of this problem is large. Please use fast input/output.

Sample Explanation

The first operation is 1 1 1 3, that is, 1241 \rightarrow 2 \rightarrow 4, so the answer is 44.

After the ninth operation, the sequence becomes 2 1 2 1 2 1.

The tenth operation is 1 1 1 5, that is, 1561 \rightarrow 5 \rightarrow 6, so the answer is 66.

Translated by ChatGPT 5