#P5854. 【模板】笛卡尔树
【模板】笛卡尔树
Description
Given a permutation of , build its Cartesian tree.
That is, build a binary tree that satisfies:
- The index of each node satisfies the property of a binary search tree.
- The weight of node is , and the weights satisfy the min-heap property.
Input Format
The first line contains an integer .
The second line contains a permutation .
Output Format
Let denote the indices of the left and right children of node (use if it does not exist).
Output one line with two integers: and .
5
4 1 3 2 5
19 21
Hint
[Sample Explanation]
[Constraints]
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号