Update It Problem

I can’t visualize how the cumulative sum is the required answer and why not query(pos) - query(pos-1) not the answer?

Hi

What we are doing in this problem is:

  1. Point updates
    two kinds of points updates, for range [l,r]
    increase the value of node a[l] by val and decrease the value of a[r+1] by val,

  2. query, fir value at index i
    it is cumulative because, if any update range has index “i” in it, then index less than i will have effect of that and we take cumulative sum of all those ( if any range that starts and end before i, it’s effect is cancelled as it’s first added then subtracted ).

This is why we are taking a cumulative sum.

See this code (not using BIT, it is just using the above update and query (to explain better above task) we are doing these throgh BIT)

https://ide.codingblocks.com/s/72021

hit like if you get it
Cheers!

1 Like