Dynamic Programming21 sections · 916 units
Open in Course

Lazy Propagation

Efficient global shifts

Some operations shift all breakpoints: 'add cc to all elements' shifts the function right by cc. Instead of updating every breakpoint, track a global offset. Apply lazily when popping. Maintain: actualValue=heapValue+offsetactualValue = heapValue + offset. When inserting, subtract offset first.

This handles shifts in O(1)O(1) instead of O(n)O(n). needed for problems with many shift operations. Global shifts are common in Slope Trick problems. Lazy propagation avoids O(n)O(n) updates per operation.