Last active
December 10, 2015 07:58
-
-
Save utkarshl/4404821 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
struct node | |
{ | |
int numleaves, add, sum; | |
void split(node& l, node& r) | |
{ | |
l.add += add; | |
l.sum += add * l.numleaves; | |
r.add += add; | |
r.sum += add * r.numleaves; | |
add=0; | |
} | |
void merge(node& l, node& r) | |
{ | |
numleaves = l.numleaves + r.numleaves; | |
add = 0; | |
sum = l.sum + r.sum; | |
} | |
}; | |
void update_single_subtree(node& n, int inc){ | |
n.add += inc; | |
n.sum += inc * n.numleaves; | |
} | |
//range_query and range_update remain same as that for previous problems |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment