Introduction
A difference array is a useful technique for applying many range updates efficiently.
Instead of changing every element in a segment , we update only a few positions in an auxiliary array. After processing all updates, we rebuild the final array using prefix sums.
This makes each range update run in time.
Idea
Given an array of length , we define its difference array diff as: