QOJ.ac

QOJ

Limite de temps : 4 s Limite de mémoire : 512 MB Points totaux : 100

#14732. stdmxeypz

Statistiques

You are given a rooted tree with $n$ nodes, rooted at $1$, where each edge has a weight of $1$. Each node has an initial value of $0$. The distance between two nodes is defined as the length of the simple path between them in the tree. You need to support the following two operations:

1 a x y z: Add $z$ to the values of all nodes in the subtree of $a$ whose distance from $a$ is congruent to $y$ modulo $x$.

2 a: Query the value of node $a$.

Input

The first line contains two integers $n$ and $m$, representing the number of nodes in the tree and the number of operations, respectively.

The second line contains $n-1$ integers, where the $i$-th integer $f_i$ represents the parent of node $i+1$.

The following $m$ lines each contain an operation of the form 1 a x y z or 2 a, as described above.

Output

For each 2 operation, output a single integer representing the answer on a new line.

Examples

Input 1

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

Output 1

5
0

Subtasks

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

For $100\%$ of the data, $1\leq n, m\leq 3\times 10^5$, $1\leq f_i\leq i$, $1\leq a\leq n$, $1\leq x\leq n$, $0\leq y < x$, and $0 \leq z < 514$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.