#FT0000042. Chèn phần tử vào dãy (Insert)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chèn phần tử vào dãy (Insert)
Insert
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Start with an empty array . For every in increasing order, insert integer so that it becomes the -th element from the beginning, using one-based positions.
More precisely, preserve the first existing elements, place immediately after them, and append all remaining elements in their original order. If , insert at the front; if , append to the end.
After all insertions, output the final array from left to right.
Input
- Line 1: integer , the number of insertions.
- Line 2: exactly integers , the insertion positions for .
Output
Print the integers of the final array , separated by spaces.
Subtasks
Subtask 1 (20 points):
- ; for every ; all inputs are integers.
Subtask 2 (30 points):
- ; for every ; all inputs are integers.
Subtask 3 (50 points):
- ; for every ; all inputs are integers.
Examples
Examples 1
Input
4
1 1 2 1
Output
4 2 3 1
Explanation
Start from . Insert at position : . Insert at position : . Insert at position : . Insert at position : .
Examples 2
Input
5
1 2 3 4 5
Output
1 2 3 4 5
Explanation
At step , , so each new element is appended at the end. The final array is .
The successive states are , , , , and . At step , inserting at position appends the new value to the end, so the relative order of earlier values never changes.