Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Compression + Fenwick and Sweep + Heap

โญโญโญ advancedโณ 30 min read๐Ÿ“ Lesson 182 of 281

Two offline workhorses: compress sparse values then count with a BIT; sweep events by start time with a min-heap of deadlines.

Offline order is a superpower

Inversions over values up to 1e9: compress, walk from the right, count already-seen smaller ranks with a Fenwick tree. Scheduling: sort by start, keep end times in a min-heap, pop what has expired. Both are 'process in a smart order, maintain the answer incrementally'. The subtle bugs live in boundaries: equal elements, touching intervals.