#P7770. 「CGOI-1」丑国旅游
「CGOI-1」丑国旅游
Description
In one part of Ugly Country, there are cities numbered from to . When a person is in city , they can and can only go to city .
People in city hate people whose ugliness value is the most. When a person with ugliness value walks from city to city , they gain a comfort value of .
Now there are people coming to travel in Ugly Country. The -th person has ugliness value and will walk from city to city . Ask for the sum of the comfort values they obtain.
Since this number may be very large, you need to output it modulo .
Since you cannot predict the next trip, the queries will be forced to be online.
Simplified statement:
Given and integers .
There are online queries. Each query gives . Compute .
Input Format
The first line contains two integers , representing the number of cities and the number of tourists.
The second line contains integers. The -th number is , with the meaning as described above.
In the next lines, each line contains three integers . Let be the total comfort value of the previous query modulo (if this is the first query, then ). Then $x_i=X\operatorname{xor}s,\;l_i=L\operatorname{xor}s,\;r_i=R\operatorname{xor}s$, where denotes bitwise XOR, and the meanings of are as described above.
Output Format
Output lines. The -th line is the -th person's total comfort value modulo .
5 2
1 2 3 4 5
1 1 3
6 1 7
2
0
Hint
Sample Explanation:
For the first query, walking from city to city gives a comfort value of . Walking from city to city gives a comfort value of . Therefore, the total comfort value is .
For the second query, the decrypted are . Walking from city to city gives a comfort value of . Walking from city to city gives a comfort value of . The total comfort value is .
Constraints:
This problem uses bundled testdata.
| ID | Special Constraints | Score | Time Limit |
|---|---|---|---|
| Subtask0 | 20pts | 1s | |
| Subtask1 | 10pts | 2s | |
| Subtask2 | is strictly increasing | ||
| Subtask3 | No special constraints | 60pts |
For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号