A binary tree organizing a fixed sequence into recursively subdivided contiguous intervals. Each node stores an aggregate for its interval. Range queries and point updates visit logarithmically many nodes; range-update variants store additional information such as a coverage count to maintain the length of a union of active intervals.
A lazy segment tree stores interval aggregates in a segment tree while representing compatible deferred updates by tags. The aggregate combination must be a monoid operation, and each tag must act on aggregates consistently with combining intervals. Tags include an identity operation and are closed under function composition.[ref]
For range addition and range sums, store , the sum and length of the interval. Combining children adds both components. Adding transforms it into , so a covered node can update its stored sum immediately without visiting every descendant. Its pending tag accumulates the addition for later lazy propagation.
For example, adding three to all four entries of changes the root sum from seven to nineteen. A query for the whole interval returns nineteen immediately. A query for just the first entry must first propagate the pending update along that entry's path. Constant-time aggregate and tag operations give interval updates and queries; an arbitrary update rule need not admit such a representation.
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 gives
On 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]

Articles by others on the same topic (0)

There are currently no matching articles.