#P3261. [JLOI2015] 城池攻占
[JLOI2015] 城池攻占
Description
Xiao Mingming recently got a new board game. In the game, you need to use knights to conquer cities.
The cities are numbered from to . Except for city , each city is governed by another city with . In other words, all cities form a rooted tree.
The knights are numbered from to , where knight has initial combat power , and his first target city is .
Each city has a defense value . If a knight's combat power is greater than or equal to the city's defense value, then the knight can capture that city; otherwise, the capture fails and the knight will fall at that city. After capturing a city, the knight's combat power will change, and then he continues to attack the city that governs this city (its parent), until he captures city , or dies.
Except for city , each city provides a combat-power change parameter . If , after capturing city , the knight's combat power increases by ; if , after capturing city , the combat power is multiplied by .
Note that each knight is simulated independently. That is, when a knight attacks a city, regardless of the outcome, it does not affect the result of other knights attacking this city.
Now the problem is: for each city, output how many knights die here; and for each knight, output how many cities he captures.
Input Format
The first line contains two positive integers , the numbers of cities and knights.
The second line contains integers, where the -th number is , the defense value of city .
Lines to : for each city from to , line contains three integers , denoting the governing (parent) city of city and the two combat-power change parameters.
Lines to : for each knight from to , line contains two integers , the initial combat power and the first city to attack.
Output Format
Output lines, each containing a nonnegative integer. The first lines give, for cities to , the number of knights who die there; the last lines give, for knights to , the number of cities they capture.
5 5
50 20 10 10 30
1 1 2
2 0 5
2 0 -10
1 0 10
20 2
10 3
40 4
20 4
35 5
2
2
0
0
0
1
1
3
1
1
Hint
For of the testdata, , , , , . It is guaranteed that when , , and that at any time the absolute value of a knight's combat power does not exceed .
Translated by ChatGPT 5
京公网安备 11011102002149号