CF1744B.Even-Odd Increments

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Even-Odd Increments

You are given nn of integers a1,a2,,ana_1, a_2, \ldots, a_n. Process qq queries of two types:

  • query of the form "0 $x_j$": add the value xjx_j to all even elements of the array aa,
  • query of the form "1 $x_j$": add the value xjx_j to all odd elements of the array aa.

Note that when processing the query, we look specifically at the odd/even value of aia_i, not its index.

After processing each query, print the sum of the elements of the array aa.

Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).

Input

The first line of the input contains an integer tt (1t104(1 \leq t \leq 10^4) — the number of test cases.

The descriptions of the test cases follow.

The first line of each test case contains two integers nn and qq (1n1 \leq n, q105q \leq 10^5) — the length of array aa and the number of queries.

The second line of each test case contains exactly nn integers: a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \leq a_i \leq 10^9) — elements of the array aa.

The following qq lines contain queries as two integers typejtype_j and xjx_j (0typej1(0 \leq type_j \leq 1, 1xj1041 \leq x_j \leq 10^4).

It is guaranteed that the sum of values nn over all test cases in a test does not exceed 10510^5. Similarly, the sum of values qq over all test cases does not exceed 10510^5.

Output

For each test case, print qq numbers: the sum of the elements of the array aa after processing a query.

Note

In the first test case, the array a=[2]a = [2] after the first query.

In the third test case, the array aa is modified as follows: [1,3,2,4,10,48][1, 3, 2, 4, 10, 48] \rightarrow [7,9,2,4,10,48][7, 9, 2, 4, 10, 48] \rightarrow [7,9,7,9,15,53][7, 9, 7, 9, 15, 53] \rightarrow [7,9,7,9,15,53][7, 9, 7, 9, 15, 53] \rightarrow [10,12,10,12,18,56][10, 12, 10, 12, 18, 56] \rightarrow [22,24,22,24,30,68][22, 24, 22, 24, 30, 68] \rightarrow [23,25,23,25,31,69][23, 25, 23, 25, 31, 69].

Samples

4
1 1
1
1 1
3 3
1 2 4
0 2
1 3
0 5
6 7
1 3 2 4 10 48
1 6
0 5
0 4
0 5
1 3
0 12
0 1
6 7
1000000000 1000000000 1000000000 11 15 17
0 17
1 10000
1 51
0 92
0 53
1 16
0 1
2
11
14
29
80
100
100
100
118
190
196
3000000094
3000060094
3000060400
3000060952
3000061270
3000061366
3000061366

在线编程 IDE

建议全屏模式获得最佳体验