Last active
August 29, 2015 14:13
-
-
Save kartikkukreja/d94541bce529a1d876d3 to your computer and use it in GitHub Desktop.
Range update example node
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 SegmentTreeNode { | |
int start, end; // this node is responsible for the segment [start...end] | |
double total; | |
void assignLeaf(double value) { | |
total = value; | |
} | |
void merge(SegmentTreeNode& left, SegmentTreeNode& right) { | |
total = left.total + right.total; | |
} | |
double query() { | |
return total; | |
} | |
// the value of the update is dummy in this case | |
void applyUpdate(bool value) { | |
total = sqrt(total); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment