Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 42s1 days 16 hours 1 minutes 42 seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 42s1 days 16 hours 1 minutes 42 seconds.

Sign in to watch this lesson
Advanced - Data Structures and Range Queries · 4:38
A Fenwick tree over the difference array turns a range update into two point updates, with a point value read back as a prefix sum. A second tree corrects the overshoot of B1(i)·i, so prefix sums, and with them range sums, come out as B1(i)·i - B2(i) after range updates, all in O(log n). Nesting the loops gives a 2D tree at O(log n · log m) per operation, and a min-tree works only for prefixes and decreasing updates.