luogu#P5220. 特工的信息流
特工的信息流
Background
is an agent.
The country where lives is being invaded, and he is given a mission: to deliver information between cities.
Problem Description
The country where lives has cities, numbered , connected by bidirectional roads. It is guaranteed that there is a unique simple path between any two cities.
Also, each city has an information flow rate .
needs to perform a total of missions. Each mission gives two cities , and is carried out as follows:
At the first moment, he starts from city and moves along the simple path between and to reach , moving to the next city in each time unit.
Every time he arrives at a city, he sends that city’s information flow to every city on the route he passes through.
We agree that at the same moment he arrives at a city, he also sends that city’s information flow to itself. We define the value of a city as the product of all information flows received by that city.
For each mission, compute the sum of the values of the cities on the simple path from to , modulo .
In addition, unfortunately, because the invaders are also acting at the same time, between his missions, some may change.
The total number of missions plus the number of times an is changed is .
Input Format
The first line contains two integers .
The second line contains integers; the -th integer represents the information flow rate of city .
The next lines each contain two integers , indicating that there is a bidirectional road between and .
The next lines each describe a mission or an update event:
- In the form
Q s t, meaning performs a mission from to . - In the form
C x k, meaning the invaders’ action makes .
Output Format
For each mission, output the total sum of information flow received by the cities on the route.
5 3
1 2 3 4 5
1 2
2 3
3 4
4 5
Q 1 5
C 1 2
Q 1 5
325
565
Hint
Constraints:
For of the testdata, .
For an additional of the testdata, , and there are no update operations.
For an additional of the testdata, the roads connect to .
For of the testdata, .
Sample Explanation:
For the first query, $1 \cdot 2 \cdot 3 \cdot 4 \cdot 5 + 2 \cdot 3 \cdot 4 \cdot 5 + 3 \cdot 4 \cdot 5 + 4 \cdot 5 + 5 = 325$.
Update: .
For the second query, $3 \cdot 2 \cdot 3 \cdot 4 \cdot 5 + 2 \cdot 3 \cdot 4 \cdot 5 + 3 \cdot 4 \cdot 5 + 4 \cdot 5 + 5 = 565$.
Translated by ChatGPT 5