#Lutece2847. The Journey of Elaina
The Journey of Elaina
Migrated from Lutece 2847 The Journey of Elaina
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
One day, Elaina travels to The Kingdom of River, which consists of cities and they are connected by tributaries.
The capital of The Kingdom of River is City located on the estuary and all the streamflow was finally converged here.
If the tributary of City passes through City and reaches the estuary, is said to be downstream of .
Now, there is streamflow for every city, which can be changed over time. The king wonders what is the sum of the streamflow for City and all its downstream cities. As the youngest, most beautiful, and most intelligent witch, Elaina, will solve this problem as easily as blowing off dust.
Input
The first line contains one integer indicating the number of cities.
The second line contains integers, indicating the array . The -th integer indicates the streamflow for City .
The third line contains integers, indicating the array . The -th integer indicates that there is a tributary between and .
The next line contains one integer indicating the number of operations.
For the next lines, the first integer indicates the type of operation.
- If , following two integers indicate the streamflow for City changing to .
- If , following one integer indicates the king's query for the sum of the streamflow for City and all its downstream cities.
Output
For every query, i.e. operation, output one line with an integer as the answer.
Samples
3
1 2 3
1 1
4
2 1
2 3
1 1 2
2 1
6
3
7
Resources
The 18th UESTC Programming Contest Preliminary