KGSS segment tree 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 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