8830: [yosupo] Tree - Vertex Add Path Sum
[Creator : ]
Description
Given a tree of $N$ vertices. Edges are $(u_i, v_i)$. Value $a_i$ is written on the vertex $i$.
Process the following $Q$ queries in order:
- 0 $p$ $x$: $a_p \gets a_p + x$
- 1 $u$ $v$: Print the sum of the values of vertices of the path between vertex $u$ and $v$ (inclusive).
Process the following $Q$ queries in order:
- 0 $p$ $x$: $a_p \gets a_p + x$
- 1 $u$ $v$: Print the sum of the values of vertices of the path between vertex $u$ and $v$ (inclusive).
Input
$N$ $Q$
$a_0$ $a_1$ ... $a_{N - 1}$
$u_0$ $v_0$
$u_1$ $v_1$
:
$u_{N - 2}$ $v_{N - 2}$
$\textrm{Query}_0$
$\textrm{Query}_1$
:
$\textrm{Query}_{Q - 1}$
$a_0$ $a_1$ ... $a_{N - 1}$
$u_0$ $v_0$
$u_1$ $v_1$
:
$u_{N - 2}$ $v_{N - 2}$
$\textrm{Query}_0$
$\textrm{Query}_1$
:
$\textrm{Query}_{Q - 1}$
Constraints
$1 \leq N, Q \leq 500000$
$0 \leq a_i, x \leq 10^9$
$0 \leq p, u_i, v_i < N$
$(u_i, v_i)$
$0 \leq a_i, x \leq 10^9$
$0 \leq p, u_i, v_i < N$
$(u_i, v_i)$
Sample 1 Input
5 5
1 10 100 1000 10000
0 1
1 2
2 3
1 4
1 0 3
1 2 4
0 1 100000
1 1 3
1 3 2
Sample 1 Output
1111
10110
101110
1100