#P4340. [SHOI2016] 随机序列
[SHOI2016] 随机序列
Description
There are numbers in a row, namely . You plan to insert a plus, minus, or multiplication sign between each adjacent pair and . Then there are possible expressions.
You are very interested in the sum of the values of all possible expressions. But that would be too easy, so you also plan to support an update operation that modifies the value of some .
Can you write a program that, after each update, outputs the sum of all possible expressions after the modification? Note that updates are permanent, which means each update is applied on top of the previous one, not on the initial sequence.
Input Format
The first line contains two positive integers and , the number of values and the number of queries. The second line contains non-negative integers, namely in order. The next lines each contain two non-negative integers and , meaning you set to , where .
It is guaranteed that for all and all , we have .
Output Format
Output lines. For each update, output one line containing a single integer, the sum of all possible expressions after the update, modulo .
5 5
9384 887 2778 6916 7794
2 8336
5 493
3 1422
1 28
4 60
890543652
252923708
942282590
228728040
608998099
Hint
- For 20% of the testdata, .
- For 50% of the testdata, .
- For 100% of the testdata, .
- 2023-11-17: Added a set of hack testdata.
Translated by ChatGPT 5
京公网安备 11011102002149号