#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 to represent an emotion.
"Mood state" A series of emotions together form a mood state. We describe a mood state as an ordered pair , where . Here, is the sum of the intensities of the emotions contained, and 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 into as . The result of resonance is a new mood state . Note that it is not necessarily true that .
"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 , its mood journey can be described as follows:
-
Initially, , where denotes the final mood state after completing the mood journey of the subtree rooted at , and is the initial mood state at node .
-
Enumerate the children of in increasing order of node index:
-
Recursively complete the mood journey of the subtree of , obtaining . At this moment, let and .
-
If , set ; otherwise, set .
-
The final is the final mood state after completing the mood journey of the subtree rooted at .
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 nodes, rooted at node . At node , the initial mood state is . Then there are operations, and each operation is one of the following two types:
-
Given a node , query the value of in , where should be recomputed for each query according to the current information.
-
Given a node and a change amount , set , and modify the corresponding . Note that may be negative, but it is guaranteed that both before and after the operation.
For each query operation, compute the corresponding answer.
Input Format
The first line contains two integers , representing the size of the tree and the number of operations.
The second line contains integers , where represents the initial weight of node .
The third line contains integers , where represents the parent of node when the tree is rooted at node .
The next 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 , 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 of the testdata, , ; the operations give , . At any time, and .
For different subtasks, the following constraints apply:
| Subtask ID | Special Property | Points | ||
|---|---|---|---|---|
| None | ||||
| None | ||||
-
Special Property : For , .
-
Special Property : It is guaranteed that when rooted at , the original tree is a binary tree. Also, for , there exists a tree path from to whose number of edges is at most .
Translated by ChatGPT 5