Last active
December 10, 2015 01:35
-
-
Save utkarshl/4358746 to your computer and use it in GitHub Desktop.
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
void update_single_node(node& n, int new_val){ | |
n.val = new_val; | |
} | |
void range_update(int root, int left_most_leaf, int right_most_leaf, int u, int v, int new_val) | |
{ | |
if(u<=left_most_leaf && right_most_leaf<=v) | |
return update_single_node(tree[root], new_val); | |
int mid = (left_most_leaf+right_most_leaf)/2, | |
left_child = root*2, | |
right_child = left_child+1; | |
tree[root].split(tree[left_child], tree[right_child]); | |
if(u < mid) range_update(left_child, left_most_leaf, mid, u, v, new_val); | |
if(v > mid) range_update(right_child, mid, right_most_leaf, u, v, new_val); | |
tree[root].merge(tree[left_child], tree[right_child]); | |
} | |
void update(int pos, int new_val){ | |
return range_update(1,1<<n,1<<(n+1),pos+(1<<n),pos+1+(1<<n),new_val) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment