2185D.md (2107B)
1 Source: https://codeforces.com/problemset/problem/2185/D 2 3 D. OutOfMemoryError 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Bessie has an array of $n$ integers $a_1, a_2, \ldots, a_n$. Bessie performs $m$ operations on the array. The $i$-th operation sets $a_{b_i} = a_{b_i} + c_i$. 22 23 Unfortunately, due to rising RAM costs, Bessie's computer has limited memory, and whenever any element of the array is greater than $h$, her computer crashes, and every element in the array is reset to its original value. 24 25 After all operations have been performed, output the array $a$. 26 27 Input 28 29 The first line of the input contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. 30 31 The first line of each test case contains three integers $n, m, h$ ($1 \le n, m \le 2 \cdot 10^5$, $1 \leq h \leq 10^9$) — the length of array $a$, the number of operations performed, and the maximum value that Bessie's computer can store without crashing. 32 33 The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le h$) — the array $a$. 34 35 The next $m$ lines contain two integers $b_i, c_i$ ($1 \leq b_i \leq n$, $0 \leq c_i \leq 10^9$) — the operations that Bessie performs on the array. 36 37 It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases does not exceed $2 \cdot 10^5$. 38 39 Output 40 41 For each test case, output the array $a$ after all operations have been performed. 42 43 Example 44 45 Input 46 47 ``` 48 3 49 50 3 4 5 51 52 1 2 1 53 54 1 4 55 56 2 4 57 58 3 3 59 60 2 0 61 62 5 3 1 63 64 1 1 1 1 1 65 66 1 1 67 68 1 1 69 70 2 1 71 72 4 4 1 73 74 1 0 0 0 75 76 1 1 77 78 4 4 79 80 3 3 81 82 4 4 83 ``` 84 85 Output 86 87 ``` 88 1 2 4 89 90 1 1 1 1 1 91 92 1 0 0 0 93 ``` 94 95 Note 96 97 For the first test case, the array $a$ is changed as follows: 98 99 * Before all operations, $a = [1, 2, 1]$. 100 * After the first operation, $a = [5, 2, 1]$. 101 * After the second operation, $a = [5, 6, 1]$, but since $6 \gt h$, the computer crashes, and $a = [1, 2, 1]$. 102 * After the third operation, $a = [1, 2, 4]$. 103 * After the fourth operation, $a = [1, 2, 4]$. 104 105 For the third test case, each operation causes the computer to crash, so $a = [1, 0, 0, 0]$.