PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#LCA0000040. Dựng cây Cartesian nhỏ nhất (Cartesian Tree)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Dựng cây Cartesian nhỏ nhất (Cartesian Tree)
Cartesian Tree
Source: Library Checker
Version: Phuoc Hung OJ Extended
Problem Statement
Given with pairwise distinct integer values, construct the min Cartesian binary tree. The tree's inorder traversal must visit indices in this order, and every node's value must be smaller than all values in its subtree.
This tree is unique. Output the parent index for each node . For the root , set (the root points to itself).
Input
- First line: .
- Second line: pairwise distinct .
Output
Print integers ; the root is its own parent.
Subtasks
General constraints (all subtasks): ; ; array values are pairwise distinct.
- Subtask 1 (20 points): ; all are pairwise distinct.
- Subtask 2 (30 points): ; all are pairwise distinct.
- Subtask 3 (50 points): ; all are pairwise distinct.
Examples
Input
3
1 0 2
Output
1 1 1
Explanation
The minimum value is at index , making index the root and its own parent. Both indices and have parent .