QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#343. Random Sequence

Statistics

You have $n$ numbers arranged in a row, denoted as $a_1, a_2, \dots, a_n$. You intend to insert either a plus sign, a minus sign, or a multiplication sign between every adjacent pair of numbers $a_i$ and $a_{i+1}$. There are $3^{n-1}$ possible expressions in total.

You are interested in the sum of the values of all possible expressions. However, since that is too simple, you also want to support a modification operation that changes the value of a specific $a_i$.

Can you write a program that outputs the sum of all possible expressions after each modification? Note that the modifications are permanent; each modification is based on the state resulting from the previous modification, rather than the initial expression.

Input

The first line contains two positive integers $n$ and $Q$, representing the number of elements and the number of queries, respectively.

The second line contains $n$ non-negative integers, representing $a_1, a_2, \dots, a_n$ in order.

The next $Q$ lines each contain two non-negative integers $t$ and $v$, indicating that $a_t$ is to be changed to $v$, where $1 \leq t \leq n$.

It is guaranteed that for all $1 \leq j \leq n$ and $1 \leq i \leq Q$, $a_j, v_i \leq 10^4$.

Output

Output $Q$ lines. For each modification, output one line containing an integer representing the sum of all possible expressions after the modification, modulo $10^9 + 7$.

Examples

Input 1

5 5
9384 887 2778 6916 7794
2 8336
5 493
3 1422
1 28
4 60

Output 1

890543652
252923708
942282590
228728040
608998099

Subtasks

Test Case ID $n, Q$
1, 2 $\leq 10$
3 - 5 $\leq 1\,000$
6 - 10 $\leq 100\,000$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.