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.

Articles by others on the same topic (0)

There are currently no matching articles.