Last active
August 29, 2015 14:13
-
-
Save kartikkukreja/17f26686853e6053e7e2 to your computer and use it in GitHub Desktop.
Range update
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(int stIndex, int start, int end, UpdateType value) { | |
if (start == end) { | |
nodes[stIndex].applyUpdate(value); | |
return; | |
} | |
int mid = (nodes[stIndex].start + nodes[stIndex].end) / 2, | |
leftChildIndex = 2 * stIndex, | |
rightChildIndex = leftChildIndex + 1; | |
if (start > mid) | |
update(rightChildIndex, start, end, value); | |
else if (end <= mid) | |
update(leftChildIndex, start, end, value); | |
else { | |
update(leftChildIndex, start, mid, value); | |
update(rightChildIndex, mid+1, end, value); | |
} | |
nodes[stIndex].merge(nodes[leftChildIndex], nodes[rightChildIndex]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment