Difference array

Add different amounts to several ranges. What does each cell contain where the ranges overlap?

Store the difference between each number and its predecessor. Use zero just before the first number.

To add d from L through R, add d at L and subtract d at R + 1. Finally, scan from left to right and accumulate the differences.

For n numbers and q updates, this takes O(n + q) time and O(n) extra space.