304431: CF847B. Preparing for Merge Sort
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Preparing for Merge Sort
题意翻译
`Ivan`有一个包含$n$个不同整数的数组。他计划将这个数组变成升序的。`Ivan`喜欢归并排序,所以他想将这个数组变成一个或多个升序数组,之后将它们合并。 他用如下的方式将原数组变成一个或多个升序数组: `Ivan`将对数组进行若干次迭代,直到数组中所有元素都被放入新数组。 对于每次迭代,`Ivan`将依次从左到右遍历每个还未放入新数组中的元素。如果某个元素是该次迭代中的第一个元素,那么它将会放入属于本次迭代的新数组中。如果某个元素不是该次迭代中的第一个元素,那么当且仅当它比属于本次迭代的新数组中最后一个数大时,它将被放入属于本次迭代的新数组的末尾。 更具体的,对于一串数$[1,3,2,5,4]$,第一次迭代将取出$[1,3,5]$这$3$个元素,第二次迭代将取出$[2,4]$这$2$个元素,因为它们是严格递增的。 输入格式:第一行一个数$n(n\leq2\times 10^5)$,表示数组中元素的个数。第二行$n$个整数,表示数组中的每个元素。 输出格式:每行若干个数,第$i$行表示属于第$i$次迭代的新数组。题目描述
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.输入输出格式
输入格式
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.
输出格式
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