Last active
August 29, 2015 14:13
-
-
Save kartikkukreja/13325ae1b1859566d083 to your computer and use it in GitHub Desktop.
FLIPCOIN SegmentTreeNode
This file contains hidden or 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] | |
| int count; | |
| bool pendingUpdate; | |
| SegmentTreeNode() : count(0), pendingUpdate(false) {} | |
| void assignLeaf(bool value) {} | |
| void merge(SegmentTreeNode& left, SegmentTreeNode& right) { | |
| count = (left.pendingUpdate ? (left.end - left.start + 1 - left.count) : left.count) | |
| + (right.pendingUpdate ? (right.end - right.start + 1 - right.count) : right.count); | |
| } | |
| int query() { | |
| return count; | |
| } | |
| bool hasPendingUpdate() { | |
| return pendingUpdate; | |
| } | |
| void applyPendingUpdate() { | |
| count = (end - start + 1) - count; | |
| pendingUpdate = false; | |
| } | |
| void addUpdate(bool value) { | |
| pendingUpdate = !pendingUpdate; | |
| } | |
| bool getPendingUpdate() { | |
| return true; | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment