CF2185D.OFME

普及-

通过率:0%

AC君温馨提醒

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

题目描述

Bessie has an array of nn integers a1,a2,…,ana_1, a_2, \ldots, a_n. Bessie performs mm operations on the array. The ii-th operation sets abi=abi+cia_{b_i} = a_{b_i} + c_i.

Unfortunately, due to rising RAM costs, Bessie's computer has limited memory, and whenever any element of the array is greater than hh, her computer crashes, and every element in the array is reset to its original value.

After all operations have been performed, output the array aa.

贝茜有一个包含 nn 个整数的数组 a1,a2,…,ana_1, a_2, \ldots, a_n。贝茜对该数组执行 mm 次操作。第 ii 次操作将 abia_{b_i} 更新为 abi+cia_{b_i} + c_i。

不幸的是,由于内存成本不断上涨,贝茜的计算机内存有限:每当数组中任意元素的值超过 hh 时,她的计算机会崩溃,并将数组中所有元素重置为初始值。

在完成所有操作后,请输出最终的数组 aa。

输入格式

The first line of the input contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains three integers n,m,hn, m, h (1≤n,m≤2⋅1051 \le n, m \le 2 \cdot 10^5, 1≤h≤1091 \leq h \leq 10^9) — the length of array aa, the number of operations performed, and the maximum value that Bessie's computer can store without crashing.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤h0 \le a_i \le h) — the array aa.

The next mm lines contain two integers bi,cib_i, c_i (1≤bi≤n1 \leq b_i \leq n, 0≤ci≤1090 \leq c_i \leq 10^9) — the operations that Bessie performs on the array.

It is guaranteed that the sum of nn and the sum of mm over all test cases does not exceed 2⋅1052 \cdot 10^5.

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

每个测试用例的第一行包含三个整数 n,m,hn, m, h(1≤n,m≤2⋅1051 \le n, m \le 2 \cdot 10^5,1≤h≤1091 \leq h \leq 10^9),分别表示数组 aa 的长度、执行的操作次数,以及 Bessie 的计算机在不崩溃的情况下所能存储的最大值。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤h0 \le a_i \le h),即数组 aa。

接下来的 mm 行每行包含两个整数 bi,cib_i, c_i(1≤bi≤n1 \leq b_i \leq n,0≤ci≤1090 \leq c_i \leq 10^9),表示 Bessie 对数组执行的操作。

保证所有测试用例中 nn 的总和与 mm 的总和均不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output the array aa after all operations have been performed.

对于每个测试用例,输出执行完所有操作后的数组 aa。

输入输出样例

  • 输入#1

    3
    3 4 5
    1 2 1
    1 4
    2 4
    3 3
    2 0
    5 3 1
    1 1 1 1 1
    1 1
    1 1
    2 1
    4 4 1
    1 0 0 0
    1 1
    4 4
    3 3
    4 4

    输出#1

    1 2 4 
    1 1 1 1 1 
    1 0 0 0

说明/提示

For the first test case, the array aa is changed as follows:

  • Before all operations, a=[1,2,1]a = [1, 2, 1].
  • After the first operation, a=[5,2,1]a = [5, 2, 1].
  • After the second operation, a=[5,6,1]a = [5, 6, 1], but since 6>h6 \gt h, the computer crashes, and a=[1,2,1]a = [1, 2, 1].
  • After the third operation, a=[1,2,4]a = [1, 2, 4].
  • After the fourth operation, a=[1,2,4]a = [1, 2, 4].

For the third test case, each operation causes the computer to crash, so a=[1,0,0,0]a = [1, 0, 0, 0].

对于第一个测试用例,数组 aa 的变化过程如下:

  • 所有操作之前,a=[1,2,1]a = [1, 2, 1]。
  • 第一次操作后,a=[5,2,1]a = [5, 2, 1]。
  • 第二次操作后,a=[5,6,1]a = [5, 6, 1],但由于 6>h6 \gt h,计算机崩溃,因此 aa 恢复为 [1,2,1][1, 2, 1]。
  • 第三次操作后,a=[1,2,4]a = [1, 2, 4]。
  • 第四次操作后,a=[1,2,4]a = [1, 2, 4]。

对于第三个测试用例,每次操作均导致计算机崩溃,因此 a=[1,0,0,0]a = [1, 0, 0, 0]。

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

首页