#P11855. [CSP-J 2022 山东] 部署

[CSP-J 2022 山东] 部署

Background

Due to the impact of the pandemic, Shandong Province canceled the CSP-J 2022 certification event, and re-created the problems in March of the following year to hold a make-up contest within the province.

Problem Description

“Letters from afar never cease; beacon fires pass through five passes even in daylight.”

In ancient times, without modern information-based warfare technology, people could only rely on beacon fires to transmit messages and on generals to plan and deploy troops to gain an advantage in war.

To minimize consumption, Country A has now built roads and marching deployment routes among nn cities, such that all nn cities are mutually reachable and there are no cycles (i.e., they form a tree structure rooted at City 11). Each city has a certain number of troops stationed.

To describe the problem clearly, we number these nn cities from 11 to nn, and City 11 is the root of the tree (the testdata guarantees that they form a tree rooted at City 11). Initially, City ii has an initial troop count of aia_{i}.

Now, to test the speed of war deployment, the general performs mm tests. Each test is one of the following two commands:

1 x y (the three numbers are separated by exactly 1 space): add yy troops to City xx and to all cities in the subtree rooted at it.

2 x y (the three numbers are separated by exactly 1 space): add yy troops to City xx and to all cities directly connected to it (including its parent node and child nodes).

After issuing the mm commands, the general calls in an adviser and makes qq queries. Each query asks for the final troop count of City xx. That adviser is Xiao Xiamai, and he asks you for help again. Please help him solve the problem (the results of the qq queries).

Input Format

The first line contains a positive integer nn, indicating the number of cities.

The second line contains nn positive integers a1,a2,ana_{1},a_{2},\dots a_{n}, indicating the initial troop count in each city.

The next n1n-1 lines each contain two integers x,yx,y, indicating that there is a road directly connecting cities xx and yy.

The next line contains a positive integer mm, indicating the number of commands.

The next mm lines each contain three positive integers p,x,yp,x,y, representing one of the two command types. When p=1p=1, it means the first command; when p=2p=2, it means the second command.

The next line contains a positive integer qq, indicating the number of queries.

The next qq lines each contain a positive integer xx, indicating a query for the final troop count of the city numbered xx.

Output Format

Output qq lines. Each line contains a positive integer, corresponding to the answer for each query.

5
1 2 3 4 5
1 2
1 3
2 4
3 5
4
1 1 2
2 2 3
1 3 3
2 5 1
4
1
2
3
4
6
7
9
9
4
1 1 1 1
1 2
1 3
1 4
1
1 1 1
2
1
2
2
2

Hint

Constraints

For 30%30\% of the testdata, 1n1000,1m10001\le n\le1000,1\le m\le1000.

For 60%60\% of the testdata, 1n105,1m105,1q1051\le n\le10^{5},1\le m\le10^{5},1\le q\le10^{5}.

Among them, for 10%10\% of the testdata the tree is a chain; for another 10%10\% the testdata contains only operation 11; for another 10%10\% the testdata contains only operation 22.

For 100%100\% of the testdata, it is guaranteed that the given cities and roads form a tree, and City 11 is the root node. $1\le n\le10^{6},1\le m\le10^{6},1\le q\le10^{6},1\le a_{i}\le10^{9},1\le x\le n,1\le y\le10$.

Hack testdata set added on 2025-06-26.

Translated by ChatGPT 5