values and a list of edits updates, where each edit is a pair [delta, index]: add delta to values[index].
Apply the edits in order. After each edit, record the sum of all even elements of the array (negative even numbers count too). Return the list of these sums.
Re-summing the whole array after every edit is too slow; keep the total up to date in O(1).values=[5, 6, 7], updates=[[1, 0], [3, 1], [-7, 2]] → [12, 6, 6]
After [1, 0] the array is [6, 6, 7], even total 12. After [3, 1] it is [6, 9, 7], total 6. After [-7, 2] it is [6, 9, 0], total 6 + 0 = 6. The answer is [12, 6, 6].
values=[-3], updates=[[1, 0], [1, 0]] → [-2, 0]
First −3 + 1 = −2 (even, total −2), then −2 + 1 = −1 (odd, total 0).
values=[5, 6, 7], updates=[[1, 0], [3, 1], [-7, 2]]
[12, 6, 6]
Run checks the first 3 tests in your browser. Submit checks all 89 tests on the server, hidden ones included.