시간 제한메모리 제한제출정답맞힌 사람정답 비율
7.5 초 2048 MB44161538.462%

문제

JOI Kingdom consists of $N$ cities numbered from $1$ to $N$. There are $N − 1$ one-way roads connecting these cities. Specifically, for each $i = 2, 3, \dots , N$, there is a road leading from city $i$ to city $P_i$. Here, it is guaranteed that $1 ≤ P_i < i$.

Each of the $N$ cities has a defined danger level. The capital city, city $1$, has a danger level of $0$. For city $i$ ($2 ≤ i ≤ N$), the danger level is defined as the number of roads traversed in the path from city $i$ to city $1$. Due to the structure of JOI Kingdom, there is exactly one unique path from any city $i$ to city $1$.

Currently, there are $K_i$ beavers living in city $i$ ($1 ≤ i ≤ N$). The president of JOI Kingdom, Bitaro, has planned a beaver relocation program. This relocation plan will be executed over $Q$ days. On the $j$-th day ($1 ≤ j ≤ Q$), one of the following three types of events will occur:

  • Relocation: All beavers living in a city with danger level $X_j$ at that moment will move to a city with danger level $Y_j$, which they can reach by traveling along one or more roads from their current city. It is guaranteed that $0 ≤ Y_j < X_j$. Due to the structure of JOI Kingdom, the relocation destination for each beaver is uniquely determined.
  • Immigration: The number of beavers living in city $A_j$ increases by $L_j$ due to immigration from outside JOI Kingdom.
  • Survey: The number of beavers currently living in city $B_j$ is surveyed.

As Bitaro’s subordinate, you realize that you can compute the number of beavers in each survey event based solely on the relocation plan’s information, without physically visiting the city.

Given the structure of JOI Kingdom, the current number of beavers living in each city, and the details of the relocation plan, write a program to compute the results of each survey event.

입력

Read the following data from the standard input.

$N$

$P_2$ $P_3$ $\cdots$ $P_N$

$K_1$ $K_2$ $\cdots$ $K_N$

$Q$

(Query $1$)

(Query $2$)

$\vdots$

(Query $Q$)

Each (Query $j$) ($1 ≤ j ≤ Q$) consists of several integers separated by spaces. Let the first integer be $T_j$, then the content of this line is as follows:

  • If $T_j = 1$, the line continues with two integers $X_j$, $Y_j$ in this order. This indicates that on day $j$, a relocation event occurs, where all beavers living in a city with danger level $X_j$ move to a city with danger level $Y_j$ that they can reach by traveling along one or more roads from their current city.
  • If $T_j = 2$, the line continues with two integers $A_j$, $L_j$ in this order. This indicates that on day $j$, an immigration event occurs, increasing the number of beavers in city $A_j$ by $L_j$.
  • If $T_j = 3$, the line continues with one integer $B_j$. This indicates that on day $j$, a survey event occurs, where the number of beavers currently living in city $B_j$ is surveyed.

출력

For each $j$ ($1 ≤ j ≤ Q$) where $T_j = 3$, output the number of beavers in city $B_j$ at that moment, one per line, in order.

제한

  • $2 ≤ N ≤ 2\, 000\, 000$.
  • $1 ≤ P_i < i$ ($2 ≤ i ≤ N$).
  • $0 ≤ K_i ≤ 100$ ($1 ≤ i ≤ N$).
  • $1 ≤ Q ≤ 2\, 000\, 000$.
  • $T_j$ is either $1$, $2$, or $3$ ($1 ≤ j ≤ Q$).
  • If $T_j = 1$, then $0 ≤ Y_j < X_j ≤ N − 1$ ($1 ≤ j ≤ Q$).
  • If $T_j = 2$, then $1 ≤ A_j ≤ N$, $1 ≤ L_j ≤ 100$ ($1 ≤ j ≤ Q$).
  • If $T_j = 3$, then $1 ≤ B_j ≤ N$ ($1 ≤ j ≤ Q$).
  • At least one $j$ ($1 ≤ j ≤ Q$) satisfies $T_j = 3$.
  • All input values are integers.

서브태스크

Let the maximum danger level of the cities be $D$.

번호배점제한
14

$D = 1$.

28

$N ≤ 20$.

313

$D ≤ 20$.

415

No queries satisfy $T_j = 2$, and at most $5$ queries satisfy $T_j = 3$.

515

At most $5$ queries satisfy $T_j = 3$.

627

No queries satisfy $T_j = 2$.

718

No additional constraints.

예제 입력 1

4
1 1 2
1 3 4 3
6
3 1
1 1 0
3 1
3 2
1 2 1
3 2

예제 출력 1

1
8
0
3

Initially, cities $1$, $2$, $3$, $4$ have $1$, $3$, $4$, $3$ beavers respectively. The danger levels of these cities are $0$, $1$, $1$, $2$, respectively.

  • On day $1$, a survey event occurs. Output $1$ on the first line, representing the number of beavers in city $1$.
  • On day $2$, a relocation event occurs. All beavers in city $2$ and city $3$ move to city $1$. At the end of day $2$, cities $1$, $2$, $3$, $4$ contain $8$, $0$, $0$, $3$ beavers, respectively.
  • On day $3$, a survey event occurs. Output $8$ on the second line.
  • On day $4$, a survey event occurs. Output $0$ on the third line.
  • On day $5$, a relocation event occurs. All beavers in city $4$ move to city $2$. At the end of day $5$, cities $1$, $2$, $3$, $4$ contain $8$, $3$, $0$, $0$ beavers, respectively.
  • On day $6$, a survey event occurs. Output $3$ on the fourth line.

This input example satisfies the constraints of subtasks 2, 3, 4, 5, 6, 7.

예제 입력 2

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

예제 출력 2

3
13
0
4
0
1

Initially, cities $1$, $2$, $3$ have $3$, $1$, $4$ beavers, respectively. The danger levels of these cities are $0$, $1$, $1$, respectively.

  • On day $1$, an immigration event occurs. The number of beavers in city $2$ increases by $5$. At the end of day $1$, cities $1$, $2$, $3$ contain $3$, $6$, $4$ beavers, respectively.
  • On day $2$, a relocation event occurs. No beavers move, as no city has a danger level of $2$.
  • On day $3$, a survey event occurs. Output $3$ on the first line.
  • On day $4$, a relocation event occurs. All beavers in city $2$ and city $3$ move to city $1$. At the end of day $4$, cities $1$, $2$, $3$ contain $13$, $0$, $0$ beavers, respectively.
  • On day $5$, a survey event occurs. Output $13$ on the second line.
  • On day $6$, a survey event occurs. Output $0$ on the third line.

Subsequent events occur similarly, but their descriptions are omitted.

This input example satisfies the constraints of subtasks 1, 2, 3, 7.

예제 입력 3

7
1 2 1 3 3 2
5 2 8 9 4 0 5
10
1 3 1
2 4 10
3 2
1 6 3
1 2 0
3 1
3 4
2 5 6
3 5
3 3

예제 출력 3

6
18
19
6
0

This input example satisfies the constraints of subtasks 2, 3, 5, 7.

채점 및 기타 정보

  • 예제는 채점하지 않는다.
  • 이 문제의 채점 우선 순위는 2이다.