A11098 | Preparing for Merge Sort
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Ivan has an array consisting of $n$ different integers. He decided to reorder all elements in increasing order. Ivan loves merge sort so he decided to represent his array with one or several increasing sequences which he then plans to merge into one sorted array.
Ivan represent his array with increasing sequences with help of the following algorithm.
While there is at least one unused number in array Ivan repeats the following procedure:
- iterate through array from the left to the right;
- Ivan only looks at unused numbers on current iteration;
- if current number is the first unused number on this iteration or this number is greater than previous unused number on current iteration, then Ivan marks the number as used and writes it down.
For example, if Ivan's array looks like \[1, 3, 2, 5, 4\] then he will perform two iterations. On first iteration Ivan will use and write numbers \[1, 3, 5\], and on second one — \[2, 4\].
Write a program which helps Ivan and finds representation of the given array with one or several increasing sequences in accordance with algorithm described above.
Ivan represent his array with increasing sequences with help of the following algorithm.
While there is at least one unused number in array Ivan repeats the following procedure:
- iterate through array from the left to the right;
- Ivan only looks at unused numbers on current iteration;
- if current number is the first unused number on this iteration or this number is greater than previous unused number on current iteration, then Ivan marks the number as used and writes it down.
For example, if Ivan's array looks like \[1, 3, 2, 5, 4\] then he will perform two iterations. On first iteration Ivan will use and write numbers \[1, 3, 5\], and on second one — \[2, 4\].
Write a program which helps Ivan and finds representation of the given array with one or several increasing sequences in accordance with algorithm described above.
输入格式
The first line contains a single integer $n$ ( $1<=n<=2·10^{5}$ ) — the number of elements in Ivan's array.
The second line contains a sequence consisting of distinct integers $a_{1},a_{2},...,a_{n}$ ( $1<=a_{i}<=10^{9}$ ) — Ivan's array.
The second line contains a sequence consisting of distinct integers $a_{1},a_{2},...,a_{n}$ ( $1<=a_{i}<=10^{9}$ ) — Ivan's array.
输出格式
Print representation of the given array in the form of one or more increasing sequences in accordance with the algorithm described above. Each sequence must be printed on a new line.
输入输出样例
输入 #1
5 1 3 2 5 4
输出 #1
1 3 5 2 4
输入 #2
4 4 3 2 1
输出 #2
4 3 2 1
输入 #3
4 10 30 50 101
输出 #3
10 30 50 101
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted