#P4004. [清华集训 2017] Hello world!
[清华集训 2017] Hello world!
Description
Xiao V has problems. His problems are very tricky, so the caring contestant ufozgg plans to weaken them. To avoid being weakened, Xiao V hides all his tricky problems in a tree with nodes (nodes are numbered from to ). Every node on the tree corresponds one-to-one with one of Xiao V’s problems. Each problem has a “trickiness value.” The problem corresponding to node (meaning the node labeled in the tree, same below) has trickiness value .
To protect his problems, the magician Xiao V cast a spell on the tree. From then on, anyone who wants to explore the tree must perform jump operations on it. Each jump operation includes a start , an end , and a step size . This means the jumper will start from and reach by jumping along the simple path on the tree. In each jump, if the shortest path distance from the current node to is no more than , the jumper jumps directly to ; otherwise, the jumper advances exactly edges along the shortest path toward .
Since Xiao V hid the problems in the tree, ufozgg cannot weaken them directly. He must jump on the tree and weaken problems along the way. Every time ufozgg passes through a node (including the start , even when ), he will take the square root of that node’s problem’s trickiness value and round it down: that is, if he passes node , he sets . We call this a weaken operation.
From time to time, ufozgg also wants to know how much he has weakened the problems. Therefore, in some jump operations he gives up weakening and instead computes the sum of trickiness values of the nodes visited in that jump. We call this a query operation.
The onlooker Lülü is very interested in Xiao V’s tricky problems and ufozgg’s weakening plan. He now wants to know the result ufozgg gets for each query operation. Can you help him?

Input Format
The first line contains a positive integer , the number of nodes in the tree.
The next line contains space-separated positive integers , describing the trickiness value on each node.
The next lines describe the tree. Each line contains two positive integers , describing an edge . It is guaranteed that , and that these edges form a tree.
The next line contains a positive integer , the total number of operations performed by ufozgg.
The next lines describe each operation in the order they are performed. Each line contains four space-separated integers , meaning the jump starts at , ends at , with step size . If , it is a weaken operation; if , it is a query operation.
Output Format
For each query operation, output a single line with one integer, the sum of the trickiness values of all problems counted in that operation.
5
1 2 3 4 5
1 2
2 3
3 4
2 5
5
1 1 4 1
1 1 4 2
0 1 5 2
1 2 4 5
1 1 5 1
10
8 6 5
Hint
For of the testdata, , , .
For all operations, it is guaranteed that and .
Translated by ChatGPT 5
京公网安备 11011102002149号