#P8479. 「GLR-R3」谷雨
「GLR-R3」谷雨
Background
“A few new leaves on rustling bamboo, a few strokes of light texture on pale mountains.”
That road from more than ten days ago was still fine, with two people together.
“We’re very lucky,” A-Ling quietly took a sip of Tianyi, who had just stopped crying and started smiling, “May heaven bless us to be in a ……”
Puffing her cheeks and pinching that soft waist, Tianyi could not help but smile as well. They were very lucky, just in time to make it in……
At the end of rows upon rows, the sky looked like mountains rising and falling under clouds, rubbed with a light cyan ink-like joy.
Their story continues, just as the crops are growing today.
Grain Rain “I climbed over a high mountain, yet ahead there is still a long, long mountain road.”
Problem Description
Old V held a small party for everyone who performed well. To liven up the atmosphere, and also to carry out the idea of safety and environmental protection, (mainly because he couldn’t come up with anything else,) Old V brought a fancy “electronic firework,” calling it “firework tree and silver flowers.”
As its name suggests, this is a tree with nodes. Node has weight , representing the brilliance of the firework style set at that node. Everyone, out of curiosity, performed a total of operations on it. Let the nodes on the path from to in the tree (including ) form the set . Each operation is one of the following:
-
Given node indices and a new brilliance , set the brilliance to for every node such that , or has an adjacent node .
-
Given , light the most “dazzling” subsegment of this string of fireworks. Specifically, maintain a sequence . Starting from , walk along tree edges toward . When you reach a node ( may be or ):
- Append to the end of sequence .
- Enumerate ’s adjacent nodes in increasing order of index. If , append to the end of .
- Finally, move to the next node.
After obtaining the final , the system will automatically light the subsegment of with the maximum sum of brilliance. The subsegment may be empty. You need to output this maximum value, i.e., for each operation 1., compute the maximum subarray sum allowing emptiness of .
Input Format
The first line contains an integer , indicating the subtask ID to which this testdata belongs.
The second line contains an integer , the number of nodes in the tree.
The third line contains integers. The -th integer is the initial weight of node .
The fourth line contains integers. To make it easier for contestants to process the data, assume node is the root of the tree. The -th integer is the parent of node , describing an edge . It is guaranteed that .
The fifth line contains an integer , the number of operations to process.
The next lines each have the format or , corresponding to the two operations described in “Description.”
Output Format
Output several lines. The -th line should contain an integer , the answer to the -th operation of type 1.
0
5
1 2 3 4 5
1 2 2 1
5
1 1 2
0 2 3 -2
1 3 4
0 4 4 1
1 3 4
15
0
1
Hint
Explanation for Sample #1

This sample is not part of the testdata, so the first line uses instead.
The 1st operation is a query. The visited nodes in order are , and the corresponding weight sequence is . The maximum subarray sum is .
The 2nd operation is an update, setting the node weights of nodes to .
The 3rd operation is a query. The visited nodes in order are , and the corresponding weight sequence is . Note that the subsegment may be empty, so the maximum subarray sum is .
The 4th operation is an update, setting the node weights of nodes to .
The 5th operation is a query. The visited nodes in order are , and the corresponding weight sequence is . The maximum subarray sum is .
Constraints
This problem uses Subtask-based scoring.
Let be the value range of the initial node weights and the node weights in update operations.
For of the data, , , , and operation parameters satisfy .
For different subtasks, the constraints are as follows:
| Subtask ID | Special Property | Score | ||
|---|---|---|---|---|
| None | ||||
| A | ||||
| B | ||||
| C | ||||
| D | ||||
| None | ||||
| E | ||||
| None |
- Special Property A: For all , holds.
- Special Property B: For all operation parameters , holds.
- Special Property C: There are no update operations.
- Special Property D: Only the -th operation is a query operation.
- Special Property E: For all parameters in query operations, when node is the root, either or is an ancestor of .
- Note: in the input only indicates the subtask ID of this data point. This data point may satisfy the constraints of other subtasks as well.
Translated by ChatGPT 5