= Lazy propagation
<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> $x\mapsto ax+b$, represent a tag by $(a,b)$. Applying $(a_1,b_1)$ first and $(a_2,b_2)$ later gives
$$
(a_2,b_2)\circ(a_1,b_1)=(a_2a_1,a_2b_1+b_2).
$$
On an interval aggregate $(s,\ell)$ it acts as $(as+b\ell,\ell)$. These formulas prove that the same combined tag works for a parent and its children. For example, doubling then adding three gives $2x+3$, whereas adding three then doubling gives $2x+6$.
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.<Lazy Segtree in the AtCoder Library documentation>[mapping, composition and id requirements]{ref}
Back to article page