Lazy propagation delays updating a segment tree node's descendants while keeping the node's own aggregate current. Before inspecting only part of its interval, apply its pending tag to both children, compose that tag with each child's pending work, and clear the parent's tag. Whole-interval queries can use the current aggregate without this descent.
Composition order matters. For affine maps , represent a tag by . Applying first and later givesOn an interval aggregate it acts as . These formulas prove that the same combined tag works for a parent and its children. For example, doubling then adding three gives , whereas adding three then doubling gives .
The lazy segment tree contract therefore needs both a correct aggregate action and correct ordered function composition. A pending tag is deferred descendant work, not permission for the parent's aggregate to be stale.[ref]
Lazy Segtree in the AtCoder Library documentation. mapping, composition and id requirements
New to topics? Read the docs here!