#P5294. [HNOI2019] 序列
[HNOI2019] 序列
Description
Given a sequence of length , and operations. Each operation changes some to . Before the first change and after each change, you need to find a non-decreasing sequence of the same length , such that is minimized, and output this minimum value.
Note that the effect of each operation is independent, i.e. each operation only affects the current query.
To avoid precision issues, we guarantee that this minimum value is a fraction, i.e. it can be written as where and are non-negative integers. Then you should output , which represents under modulo arithmetic. Here is a large prime.
Input Format
The first line contains two non-negative integers , representing the sequence length and the number of operations.
The second line contains positive integers separated by spaces, representing .
The next lines each contain two positive integers , meaning to change to .
Output Format
Output lines, each containing one integer. The -th line should output the answer after the -th change. In particular, the first line should be the answer for the initial state.
5 3
9 2 4 6 4
1 1
1 4
5 6
28
2
4
26
Hint
Sample Explanation
For the first query, an optimal sequence is .
For the second query, an optimal sequence is .
For the third query, an optimal sequence is .
For the fourth query, an optimal sequence is .
The sample is a special case where there exists an optimal solution with all being integers.
Constraints and Notes
For the first of the testdata, it is guaranteed that , , and there exists an optimal solution with all being integers.
For the first of the testdata, it is guaranteed that .
For another of the testdata, it is guaranteed that .
For another of the testdata, it is guaranteed that .
For all testdata, it is guaranteed that , , .
Translated by ChatGPT 5
京公网安备 11011102002149号