I have an array, and for each query, I need to add x to all the values from index l to index r. For example, if I had the array 1 0 1 0 1, and three queries of the form l, r, x:
1 2 1 3 5 3 1 5 2
I'd have to add 1 to values in the array from index 1 to index 2, then 3 from index 3 to index 5, then 2 from index 1 to index 5. The final array would be 4 3 6 5 6. How would this be done efficiently? I tried simply iterating over the values from l to r, but that did not work.