#K8851. Perform Array Operations
Perform Array Operations
Perform Array Operations
You are given an array of n integers and a sequence of q operations. Each operation is represented by three integers \( l \), \( r \), and \( k \) which means that you should add \( k \) to every element in the subarray from index \( l \) to \( r \) (1-indexed).
After processing all operations, output the final state of the array.
For example, if the array is [1, 2, 3, 4, 5] and the operations are:
- Operation 1: (1, 3, 1) → add 1 to elements at positions 1, 2, 3
- Operation 2: (2, 5, -2) → subtract 2 from elements at positions 2, 3, 4, 5
- Operation 3: (3, 3, 5) → add 5 to the element at position 3
Then the final array becomes: [2, 1, 7, 2, 3].
inputFormat
The input is given via stdin with the following format:
- The first line contains two integers \( n \) and \( q \): the number of elements in the array and the number of operations.
- The second line contains \( n \) space-separated integers, representing the elements of the array.
- Each of the following \( q \) lines contains three integers \( l \), \( r \), and \( k \) describing an operation.
outputFormat
Output the final state of the array as \( n \) space-separated integers on a single line using stdout.
## sample5 3
1 2 3 4 5
1 3 1
2 5 -2
3 3 5
2 1 7 2 3