Last active
August 29, 2015 14:09
-
-
Save kartikkukreja/f47b1dd6483d3fe72af0 to your computer and use it in GitHub Desktop.
KGSS segment tree node
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 maxNum, secondMaxNum; | |
void assignLeaf(int num) { | |
maxNum = num; | |
secondMaxNum = -1; | |
} | |
void merge(SegmentTreeNode& left, SegmentTreeNode& right) { | |
maxNum = max(left.maxNum, right.maxNum); | |
secondMaxNum = min(max(left.maxNum, right.secondMaxNum), max(right.maxNum, left.secondMaxNum)); | |
} | |
int getValue() { | |
return maxNum + secondMaxNum; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment