0

Please help me understand this statement in lazy propagation for segment trees.

I would have expected incrementing by merely Lazy[treeIndex]:

tree[treeIndex] += Lazy[treeIndex]

Context:

void RangeUpdate(int node, int st, int end, int l, int r, long long val)
{
if(Lazy[node] != 0)  // if node is lazy then update it
{
    tree[node] += (end-st+1)*Lazy[node];

Full code as found here—

https://gist.githubusercontent.com/Princeraaz/0bcc10f8347c26a035fc7c6bb6ed27f9/raw/4c91093a518ebeed955daf1c3588d8a9bf2edf82/Lazy_RangeUpdate.cpp

Sourced from: https://medium.com/nybles/understanding-range-queries-and-updates-segment-tree-lazy-propagation-and-mos-algorithm-d2cd2f6586d8

1 Answers1

0

Perhaps it means the sum of updates to its descendent leafs— last leaf in its range minus first leaf, plus 1 to include the first leaf also.