#P9158. 「GLR-R4」小暑

「GLR-R4」小暑

Background

"Long-growing warm winds blow at dawn, lotus leaves lightly open, and roses fall."


The last rehearsal performance at school!

From the first time on stage until now, from the empty playground after school as once agreed to today’s training room filled with sweat day and night, have their promises to each other changed?

"The guitar on our shoulders and our little dreams need to grow strong wings for them!"


Minor Heat "Can you hear me now? I will become your pride from now on. We are setting off right now. Everything is just right."

Background

Problem Description

Do you still remember? You are Tianyi and the others’ professional analyst. Besides the performers’ performance, the audience’s emotional fluctuations are also important targets for analysis. After unremitting effort, you proposed the following indicators (the setter has already been eliminated by you, but please still read patiently):

"Emotion" We use an intensity vNv\in\mathbb N^\star to represent an emotion.

"Mood state" A series of emotions together form a mood state. We describe a mood state as an ordered pair M=(s,f)M=(s,f), where s,fNs,f\in\mathbb N^\star. Here, ss is the sum of the intensities of the emotions contained, and ff is the intensity of a certain characteristic emotion.

"Resonance" Two mood states can be fused into a new mood state through resonance. We denote the resonance that fuses M2=(s2,f2)M_2=(s_2,f_2) into M1=(s1,f1)M_1=(s_1,f_1) as M1+M2M_1+M_2. The result of resonance is a new mood state M=M1+M2=(s1+s2,f1)M=M_1+M_2=(s_1+s_2,f_1). Note that it is not necessarily true that M1+M2=M2+M1M_1+M_2=M_2+M_1.

"Mood journey" On a rooted tree, the process of resonating mood states along the tree structure is called a mood journey. For the subtree rooted at rr, its mood journey can be described as follows:

  1. Initially, ArMrA_r\gets M_r, where AxA_x denotes the final mood state after completing the mood journey of the subtree rooted at xx, and MxM_x is the initial mood state at node xx.

  2. Enumerate the children xx of rr in increasing order of node index:

    • Recursively complete the mood journey of the subtree of xx, obtaining AxA_x. At this moment, let Ar=(sr,fr)A_r=(s_r,f_r) and Ax=(sx,fx)A_x=(s_x,f_x).

    • If srsxs_r\ge s_x, set ArAr+AxA_r\gets A_r+A_x; otherwise, set ArAx+ArA_r\gets A_x+A_r.

The final ArA_r is the final mood state after completing the mood journey of the subtree rooted at rr.


To study the psychological changes of a specific audience member, you need to monitor the above indicators at all times. Now you are given a rooted tree with nn nodes, rooted at node 11. At node xx, the initial mood state is Mx=(ax,ax)M_x=(a_x,a_x). Then there are qq operations, and each operation is one of the following two types:

  1. Given a node xx, query the value of fxf_x in Ax=(sx,fx)A_x=(s_x,f_x), where AxA_x should be recomputed for each query according to the current information.

  2. Given a node xx and a change amount dd, set axax+da_x\gets a_x+d, and modify the corresponding MxM_x. Note that dd may be negative, but it is guaranteed that ax>0a_x>0 both before and after the operation.

For each query operation, compute the corresponding answer.

Input Format

The first line contains two integers n,qn,q, representing the size of the tree and the number of operations.

The second line contains nn integers a1,a2,,ana_1,a_2,\cdots,a_n, where aia_i represents the initial weight of node ii.

The third line contains n1n-1 integers p2,p3,,pnp_2,p_3,\cdots,p_n, where pip_i represents the parent of node ii when the tree is rooted at node 11.

The next qq lines each have the format 1 x or 2 x d, corresponding to the two types of operations described above.

Output Format

For each operation of type 11, output one line containing one integer, representing the required answer.

5 10
2 10 1 10 3
1 2 3 2
2 1 3
1 3
1 5
2 3 5
2 3 2
1 5
2 5 6
1 3
2 5 -1
2 3 0
10
3
3
10

Hint

Constraints and Conventions

For 100%100\% of the testdata, 1n,q2×1051\le n,q\le2\times10^5, 1pi<i1\le p_i<i; the operations give x[1,n]x\in[1,n], d[1018,1018]d\in[-10^{18},10^{18}]. At any time, ax1a_x\ge 1 and x=1nax1018\sum_{x=1}^na_x\le10^{18}.

For different subtasks, the following constraints apply:

Subtask ID nn qq Special Property Points
11 103\leq 10 ^ 3 None 1010
22 2×105\leq 2 \times 10 ^ 5 A\textbf A 2020
33 2×105\le 2 \times 10 ^ 5 2×105\le 2 \times 10 ^ 5 B\textbf B
44 2×105\leq 2 \times 10 ^ 5 None 5050
  • Special Property A\textbf A: For i[2,n]i\in[2,n], pi=i1p_i=i-1.

  • Special Property B\textbf B: It is guaranteed that when rooted at 11, the original tree is a binary tree. Also, for i[2,n]i\in[2,n], there exists a tree path from 11 to ii whose number of edges is at most 2020.

Translated by ChatGPT 5