最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

CF 1744B - Even-Odd Increments

2023-08-18 16:14 作者:您是打尖兒還是住店呢  | 我要投稿

You are given n of integers a1,a2,…,an. Process q queries of two types:

query of the form "0 xj": add the value xj to all even elements of the array a,query of the form "1 xj": add the value xj to all odd elements of the array a.

Note that when processing the query, we look specifically at the odd/even value of ai, 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++).


Input

The first line of the input contains an integer t (1≤t≤104) — 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≤n, q≤105) — the length of array a and the number of queries.

The second line of each test case contains exactly n integers: a1,a2,…,an (1≤ai≤109) — elements of the array a.

The following q lines contain queries as two integers typej and xj (0≤typej≤1, 1≤xj≤104).

It is guaranteed that the sum of values n over all test cases in a test does not exceed 105. Similarly, the sum of values q over all test cases does not exceed 105.

Output

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

----------------------------------------

給定 n 個(gè)整數(shù) a1,a2,…,an。 處理兩種類型的 q 查詢:

“0 xj”形式的查詢:將值 xj 添加到數(shù)組 a 的所有偶數(shù)元素,“1 xj”形式的查詢:將值 xj 添加到數(shù)組 a 的所有奇數(shù)元素。

請(qǐng)注意,在處理查詢時(shí),我們專門查看 ai 的奇/偶值,而不是其索引。

處理完每個(gè)查詢后,打印數(shù)組 a 的元素之和。

請(qǐng)注意,某些測(cè)試用例的答案不適合 32 位整數(shù)類型,因此您應(yīng)該在編程語言中至少使用 64 位整數(shù)類型(例如 C++ 的 long long)。


輸入

輸入的第一行包含一個(gè)整數(shù) t (1≤t≤104) — 測(cè)試用例的數(shù)量。

測(cè)試用例的描述如下。

每個(gè)測(cè)試用例的第一行包含兩個(gè)整數(shù)n和q(1≤n,q≤105)——數(shù)組a的長(zhǎng)度和查詢的數(shù)量。

每個(gè)測(cè)試用例的第二行恰好包含 n 個(gè)整數(shù):a1,a2,…,an (1≤ai≤109) — 數(shù)組 a 的元素。

以下 q 行包含兩個(gè)整數(shù) typej 和 xj (0≤typej≤1, 1≤xj≤104) 的查詢。

保證一次測(cè)試中所有測(cè)試用例的 n 值之和不超過 105。同樣,所有測(cè)試用例的 q 值之和不超過 105。

輸出

對(duì)于每個(gè)測(cè)試用例,打印 q 個(gè)數(shù)字:處理查詢后數(shù)組 a 的元素之和。

-------------------------------------

代碼明明沒問題的,結(jié)果報(bào)錯(cuò)了好幾次。。。


CF 1744B - Even-Odd Increments的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
邯郸县| 陇西县| 西乌珠穆沁旗| 郎溪县| 凤山市| 江北区| 鲁甸县| 当雄县| 弋阳县| 巍山| 营山县| 年辖:市辖区| 青浦区| 陕西省| 岳池县| 获嘉县| 丹江口市| 营口市| 静安区| 高陵县| 商洛市| 军事| 德阳市| 和静县| 肥东县| 姚安县| 普洱| 迁安市| 高要市| 政和县| 双桥区| 托克托县| 色达县| 都兰县| 多伦县| 光山县| 曲阜市| 卢龙县| 惠东县| 呼图壁县| 宁远县|