Approach hintTry it first, then revealHide
Build the tree recursively: the maximum of a segment is its root, and the parts to its left and right form the two subtrees. Pass the current depth down the recursion; O(n^2) fits the limits.
Build the tree recursively: the maximum of a segment is its root, and the parts to its left and right form the two subtrees. Pass the current depth down the recursion; O(n^2) fits the limits.