309846: CF1744B. Even-Odd Increments

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Even-Odd Increments

题意翻译

给定一个长度为 $n$ 的数列,有 $q$ 次操作,问每次执行完操作后数列的总和。 共有两种操作: - $\texttt{0\space x}$,给所有偶数加上 $x$; - $\texttt{1\space x}$,给所有奇数加上 $x$;`

题目描述

You are given $ n $ of integers $ a_1, a_2, \ldots, a_n $ . Process $ q $ queries of two types: - query of the form "0 $ x_j $ ": add the value $ x_j $ to all even elements of the array $ a $ , - query of the form "1 $ x_j $ ": add the value $ x_j $ to all odd elements of the array $ a $ . Note that when processing the query, we look specifically at the odd/even value of $ a_i $ , not its index. After processing each query, print the sum of the elements of the array $ a $ . 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++).

输入输出格式

输入格式


The first line of the input contains an integer $ t $ $ (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 $ n $ and $ q $ ( $ 1 \leq n $ , $ q \leq 10^5 $ ) — the length of array $ a $ and the number of queries. The second line of each test case contains exactly $ n $ integers: $ a_1, a_2, \ldots, a_n $ ( $ 1 \leq a_i \leq 10^9 $ ) — elements of the array $ a $ . The following $ q $ lines contain queries as two integers $ type_j $ and $ x_j $ $ (0 \leq type_j \leq 1 $ , $ 1 \leq x_j \leq 10^4 $ ). It is guaranteed that the sum of values $ n $ over all test cases in a test does not exceed $ 10^5 $ . Similarly, the sum of values $ q $ over all test cases does not exceed $ 10^5 $ .

输出格式


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

输入输出样例

输入样例 #1

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

输出样例 #1

2
11
14
29
80
100
100
100
118
190
196
3000000094
3000060094
3000060400
3000060952
3000061270
3000061366
3000061366

说明

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

Input

题意翻译

给定一个长度为 $n$ 的数列,有 $q$ 次操作,问每次执行完操作后数列的总和。 共有两种操作: - $\texttt{0\space x}$,给所有偶数加上 $x$; - $\texttt{1\space x}$,给所有奇数加上 $x$;`

Output

**题目大意:**

给定一个长度为 $ n $ 的数列,有 $ q $ 次操作,每次操作后输出数列的总和。操作分为两种:

- `0 x`:给所有偶数加上 $ x $;
- `1 x`:给所有奇数加上 $ x $。

**输入数据格式:**

- 第一行包含一个整数 $ t $($ 1 \leq t \leq 10^4 $),表示测试用例的数量。
- 每个测试用例包含三部分:
- 第一行包含两个整数 $ n $ 和 $ q $($ 1 \leq n, q \leq 10^5 $),分别表示数列的长度和操作的数量。
- 第二行包含 $ n $ 个整数,表示数列的初始值 $ a_1, a_2, \ldots, a_n $($ 1 \leq a_i \leq 10^9 $)。
- 接下来 $ q $ 行,每行包含两个整数 $ type_j $ 和 $ x_j $($ 0 \leq type_j \leq 1 $,$ 1 \leq x_j \leq 10^4 $),表示一种操作。

保证所有测试用例中 $ n $ 的总和不超过 $ 10^5 $,$ q $ 的总和也不超过 $ 10^5 $。

**输出数据格式:**

- 对于每个测试用例,输出 $ q $ 个整数,分别表示每次操作后数列的总和。

**输入输出样例:**

**输入样例 #1:**
```
4
1 1
1
3 3
1 2 4
6 7
1 3 2 4 10 48
6 7
1000000000 1000000000 1000000000 11 15 17
```

**输出样例 #1:**
```
2
11
14
29
80
100
100
100
118
190
196
3000000094
3000060094
3000060400
3000060952
3000061270
3000061366
3000061366
```**题目大意:** 给定一个长度为 $ n $ 的数列,有 $ q $ 次操作,每次操作后输出数列的总和。操作分为两种: - `0 x`:给所有偶数加上 $ x $; - `1 x`:给所有奇数加上 $ x $。 **输入数据格式:** - 第一行包含一个整数 $ t $($ 1 \leq t \leq 10^4 $),表示测试用例的数量。 - 每个测试用例包含三部分: - 第一行包含两个整数 $ n $ 和 $ q $($ 1 \leq n, q \leq 10^5 $),分别表示数列的长度和操作的数量。 - 第二行包含 $ n $ 个整数,表示数列的初始值 $ a_1, a_2, \ldots, a_n $($ 1 \leq a_i \leq 10^9 $)。 - 接下来 $ q $ 行,每行包含两个整数 $ type_j $ 和 $ x_j $($ 0 \leq type_j \leq 1 $,$ 1 \leq x_j \leq 10^4 $),表示一种操作。 保证所有测试用例中 $ n $ 的总和不超过 $ 10^5 $,$ q $ 的总和也不超过 $ 10^5 $。 **输出数据格式:** - 对于每个测试用例,输出 $ q $ 个整数,分别表示每次操作后数列的总和。 **输入输出样例:** **输入样例 #1:** ``` 4 1 1 1 3 3 1 2 4 6 7 1 3 2 4 10 48 6 7 1000000000 1000000000 1000000000 11 15 17 ``` **输出样例 #1:** ``` 2 11 14 29 80 100 100 100 118 190 196 3000000094 3000060094 3000060400 3000060952 3000061270 3000061366 3000061366 ```

加入题单

算法标签: