CF1744B.Even-Odd Increments

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 xjx_j": add the value xjx_j to all even elements of the array aa,
  • query of the form "1 xjx_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++).

给你 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n。你需要处理 qq 个查询,查询分为两类:

  • 形如 “0 xjx_j” 的查询:将值 xjx_j 加到数组 aa 中所有偶数元素上;
  • 形如 “1 xjx_j” 的查询:将值 xjx_j 加到数组 aa 中所有奇数元素上。

注意:在处理查询时,我们依据的是元素 aia_i 本身的值的奇偶性,而非其下标 ii 的奇偶性。

每次查询处理完毕后,请输出此时数组 aa 中所有元素的和。

请注意:某些测试用例的答案可能超出 32 位整数范围,因此你应至少使用 64 位整数类型(例如 C++ 中的 long long)。

输入格式

The first line of the input contains an integer tt (1≤t≤104(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 (1≤n1 \leq n, q≤105q \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 (1≤ai≤1091 \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 (0≤typej≤1(0 \leq type_j \leq 1, 1≤xj≤1041 \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.

输入的第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4)—— 表示测试用例的数量。

接下来是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 qq(1≤n,q≤1051 \leq n, q \leq 10^5)—— 分别表示数组 aa 的长度以及查询的数量。

每个测试用例的第二行包含恰好 nn 个整数:a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \leq a_i \leq 10^9)—— 表示数组 aa 的元素。

接下来的 qq 行每行包含一个查询,由两个整数 typejtype_j 和 xjx_j 组成(0≤typej≤10 \leq type_j \leq 1,1≤xj≤1041 \leq x_j \leq 10^4)。

保证在一个测试中,所有测试用例的 nn 值之和不超过 10510^5;同理,所有测试用例的 qq 值之和也不超过 10510^5。

输出格式

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

对于每个测试用例,输出 qq 个数字:每次处理完一个查询后数组 aa 中所有元素的和。

输入输出样例

  • 输入#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]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].

在第一个测试用例中,第一次查询后数组 a=[2]a = [2]。

在第三个测试用例中,数组 aa 按如下方式被修改:[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]。

输入解题思路,AI测评打分。不知道怎么写?

首页