#C875. Array Range Operations
Array Range Operations
Array Range Operations
You are given an array of n integers and q operations. Each operation is represented as a tuple \((l, r, d)\) where you must add the integer d to every element in the array from index l to r (the indices are 1-indexed).
Your task is to compute and print the final state of the array after applying all the operations sequentially.
The effect of each operation on the array can be mathematically described by the formula:
$$A'_i = A_i + \sum_{\substack{(l,r,d)\\ l \le i \le r}} d $$where \(A_i\) is the original element at index i, and \(A'_i\) is the updated element.
This problem can be efficiently solved using the difference array technique.
inputFormat
The input is read from standard input and is structured as follows:
- The first line contains two integers \(n\) and \(q\), where \(n\) is the number of elements in the array and \(q\) is the number of operations.
- The second line contains \(n\) integers representing the elements of the array.
- Each of the next \(q\) lines contains three integers \(l\), \(r\), and \(d\) which represent an operation: add \(d\) to each element of the array in the index range \([l, r]\).
outputFormat
Output the final state of the array on a single line. Separate each element by a space.
## sample5 3
1 2 3 4 5
1 3 2
2 5 3
3 4 1
3 7 9 8 8