Last active
August 29, 2015 14:03
-
-
Save kartikkukreja/6e5677a112f3d4111ea9 to your computer and use it in GitHub Desktop.
Point Updates and Range Queries with BIT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add v to A[p] | |
update(p, v): | |
for (; p <= N; p += p&(-p)) | |
ft[p] += v | |
# Return sum A[1...b] | |
query(b): | |
sum = 0 | |
for(; b > 0; b -= b&(-b)) | |
sum += ft[b] | |
return sum | |
# Return sum A[a...b] | |
query(a, b): | |
return query(b) - query(a-1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment