Created
June 17, 2018 22:40
-
-
Save sazid/23fcdfc0c85e95be3b1480ae9cf61e7b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
void update(int node, int b, int e, int i, int newval) { | |
// index is out of range | |
if (b > i || e < i) return; | |
// we're at leaf node | |
if (b == i && e == i) { | |
tree[node] = newval; | |
a[i] = newval; | |
return; | |
} | |
int left = 2*node; | |
int right = 2*node + 1; | |
int mid = (b + e)/2; | |
update(left, b, mid, i, newval); | |
update(right, mid + 1, e, i, newval); | |
tree[node] = tree[left] + tree[right]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment