Skip to content

Instantly share code, notes, and snippets.

@utkarshl
Last active December 10, 2015 07:58
Show Gist options
  • Save utkarshl/4404821 to your computer and use it in GitHub Desktop.
Save utkarshl/4404821 to your computer and use it in GitHub Desktop.
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