Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
KGSS segment tree node
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