#C11948. Range Update and Sequence Modification

    ID: 41320 Type: Default 1000ms 256MiB

Range Update and Sequence Modification

Range Update and Sequence Modification

You are given a sequence of integers and a series of operations. Each operation is defined by three integers (l), (r), and (v), which means that you should add the value (v) to every element in the subarray from index (l) to (r) (inclusive). The goal is to modify the sequence by applying all the operations in the given order.

For example, if the sequence is [1, 2, 3, 4, 5] and the operations are ((1, 3, 2)), ((2, 4, 3)), and ((1, 5, -1)), the final modified sequence will be [2, 6, 7, 6, 4].

This problem can be efficiently solved using the prefix sum (difference array) technique. For an operation ((l, r, v)), you do: [ A[l] += v,] [ A[r+1] -= v \quad \text{(if } r+1 \leq n \text{)} ]

After processing all operations, a cumulative sum through the array will give the final modified sequence.

inputFormat

The first line contains two integers (n) and (q) representing the length of the sequence and the number of operations. The second line contains (n) space-separated integers representing the initial sequence. The next (q) lines each contain three integers (l), (r), and (v), indicating that (v) should be added to every element in the range from index (l) to (r) (1-indexed).

outputFormat

Output the modified sequence as a single line of (n) space-separated integers after all operations have been applied.## sample

5 3
1 2 3 4 5
1 3 2
2 4 3
1 5 -1
2 6 7 6 4

</p>