#P10407. 「SMOI-R1」Game
「SMOI-R1」Game
Background
myz really enjoys playing a virus game.
Problem Description
In this game, there are initially viruses, and each virus has a hazard value of .
After some time, a virus mutates and splits into two viruses. The virus on the right has a hazard value higher than the virus on the left. A virus that has mutated will not mutate again.
Each virus has a mutation limit . When the virus mutates up to , it stops mutating. That is, the -th virus will finally split into a virus sequence with hazard values . When all viruses have finished mutating, the game starts. The final sequence is $\{1,2,3,\ldots,b_1,1,2,3,\ldots,b_2,\ldots,1,2,3,\ldots,b_n\}$.
In each game, the system selects an interval, and myz needs to kill all viruses in this interval. If the maximum hazard value among the viruses in this interval is , then myz needs to spend energy to eliminate them.
Since myz does not know which interval the system will choose, he wants to know the sum of the energy values required for every interval.
Because the answer is too large, output the answer modulo .
Input Format
The first line contains an integer , indicating that there are initially viruses.
The second line contains integers. The -th integer is , indicating the mutation limit of the -th virus.
Output Format
Output one integer, representing the total energy myz needs to spend, modulo .
2
2 3
33
Hint
Sample Explanation
In the first sample, the viruses finally split into . The sum of the minimum costs for intervals $[1,1],[1,2],[1,3],[1,4],[1,5],[2,2],[2,3],[2,4],[2,5],[3,3],[3,4],[3,5],[4,4],[4,5],[5,5]$ is .
Constraints
This problem uses bundled testdata.
| subtask ID | Special Property | Score | ||
|---|---|---|---|---|
| None | ||||
| A | ||||
| None |
Special Property A: .
For of the testdata, it is guaranteed that and .
Translated by ChatGPT 5