Hello all.
Can anyone explain why this code(for range update and point query) works? When i read BIT from topcoder tutorial they said that query(x) returns array[1]+array[2]...+array[x] but here query(x) returns only array[x].
CODE:
update(p, v): for (; p <= N; p += p&(-p)) ft[p] += v
update(a, b, v):
update(a, v)
update(b + 1, -v)
query(b):
sum = 0
for(; b > 0; b -= b&(-b)) sum += ft[b]
return sum
PS : the above code is taken from : http://kartikkukreja.wordpress.com/2013/12/02/range-updates-with-bit-fenwick-tree/