You maintain n counters at positions 1..n, all initially 0. You are given m operations; each operation l r v means: add v to every counter at positions l..r inclusive. After applying all m operations in the given order, print the final array.
Line 1: two integers n m.
Next m lines: three integers l r v each.
n space-separated integers: the final value of counters 1..n.
Example 1
Input
5 2 1 3 4 2 5 -1
Expected
4 3 3 -1 -1
Explanation
Start [0,0,0,0,0]. Op1 adds 4 to positions 1-3: [4,4,4,0,0]. Op2 adds -1 to positions 2-5: [4,3,3,-1,-1].
Example 2
Input
3 0
Expected
0 0 0
Explanation
No operations are applied, so the array stays [0,0,0].
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →