#P7710. [Ynoi2077] stdmxeypz

[Ynoi2077] stdmxeypz

Problem Description

You are given a rooted tree with edge weight 11 and root at node 11. Each node has a node value initially equal to 00. The distance between two nodes is defined as the length of the simple path between them in the tree. You need to support two types of operations:

1 a x y z: For all nodes in the subtree of aa whose distance to aa modulo xx equals yy, add zz to their node values.

2 a: Query the node value of node aa.

Input Format

The first line contains two integers n,mn, m, meaning the tree has nn nodes and there are mm operations.

The second line contains n1n - 1 integers. The ii-th integer fif_i denotes the parent of node i+1i + 1 in the tree.

Then follow mm lines, each in the form 1 a x y z or 2 a, representing the operations above.

Output Format

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

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

Hint

Idea: nzhtl1477, Solution: nzhtl1477, Code: nzhtl1477, Data: nzhtl1477

Constraints: For 100%100\% of the testdata, 1n,m3×1051\leq n, m\leq 3\times 10^5, 1fii1\leq f_i\leq i, 1an1\leq a\leq n, 1xn1\leq x\leq n, 0y<x0\leq y < x, 0z<5140 \leq z < 514.

Translated by ChatGPT 5