Array: . You want to add to indices through . Difference array starts as: .
Update: , .
Now .
Take prefix sum of : .
Elements at indices increased by . The rest stayed at .
Trace an example
Array: . You want to add to indices through . Difference array starts as: .
Update: , .
Now .
Take prefix sum of : .
Elements at indices increased by . The rest stayed at .