0Pricing
Competitive Programming Academy · Lesson

Difference Arrays for Range Updates

Apply many add-on-range operations fast.

Flip the Problem

Prefix sums answered range queries fast. A difference array flips that to apply many range updates fast. 🔁

The Slow Way

Adding a value to every element in a range, repeated many times, costs O(n) per update. Across q updates that cost explodes.

All lessons in this course

  1. Build a Prefix Sum Array
  2. Sum Any Range with Subtraction
  3. Count Subarrays with a Target Sum
  4. Difference Arrays for Range Updates
← Back to Competitive Programming Academy