Problem8832--[yosupo] Tree - Vertex Add Subtree Sum

8832: [yosupo] Tree - Vertex Add Subtree Sum

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 512 MiB

Description

Given rooted tree of $N$ vertices. The root of tree is a vertex $0$. A value of vertex $i$ is $a_i$, and a parent of it is $p_i$. Process the following $Q$ queries in order:
- 0 $u$ $x$: $a_u \gets a_u + x$
- 1 $u$: Print the sum of values of subtree, whose root is $u$.

Input

$N$ $Q$
$a_0$ $a_1$ ... $a_{N - 1}$
$p_1$ $p_2$ ... $p_{N - 1}$
$\textrm{Query}_0$
$\textrm{Query}_1$
:
$\textrm{Query}_{Q - 1}$

Constraints

$1 \leq N, Q \leq 500,000$
$0 \leq p_i < i$
$0 \leq a_i, x \leq 10^9$

Sample 1 Input

5 5
1 10 100 1000 10000
0 1 2 2
1 1
1 2
0 1 100000
1 0
1 3

Sample 1 Output

11110
11100
111111
1000

HINT

相同题目:yosupo

Source/Category