⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 19m 29s17 days 22 hours 19 minutes 29 seconds.
⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 19m 29s17 days 22 hours 19 minutes 29 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.