English · Original
Chinese · Translation
Formal · Original
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.
## Input
The first line contains a single integer _n_ (1 ≤ _n_ ≤ 2·105) — 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_ ≤ 109) — Ivan's array.
## Output
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.
[samples]
[{"iden":"statement","content":"Ivan 有一个包含 #cf_span[n] 个不同整数的数组。他决定将所有元素按升序重新排列。Ivan 喜欢归并排序,因此他打算将他的数组表示为一个或多个递增序列,然后将这些序列归并为一个有序数组。\n\nIvan 使用以下算法将他的数组表示为递增序列。\n\n当数组中至少还有一个未使用的数字时,Ivan 重复以下过程:\n\n例如,如果 Ivan 的数组为 _[1, 3, 2, 5, 4]_,则他会进行两次迭代。第一次迭代中,Ivan 使用并写出数字 _[1, 3, 5]_,第二次迭代中则使用 _[2, 4]_。\n\n请编写一个程序,帮助 Ivan 根据上述算法,将给定数组表示为一个或多个递增序列。\n\n第一行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 2·105]) —— Ivan 数组中元素的个数。\n\n第二行包含一个由互不相同的整数组成的序列 #cf_span[a1, a2, ..., an] (#cf_span[1 ≤ ai ≤ 109]) —— Ivan 的数组。\n\n请按照上述算法,以一个或多个递增序列的形式输出数组的表示。每个序列必须单独占一行。"},{"iden":"input","content":"第一行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 2·105]) —— Ivan 数组中元素的个数。第二行包含一个由互不相同的整数组成的序列 #cf_span[a1, a2, ..., an] (#cf_span[1 ≤ ai ≤ 109]) —— Ivan 的数组。"},{"iden":"output","content":"请按照上述算法,以一个或多个递增序列的形式输出数组的表示。每个序列必须单独占一行。"},{"iden":"examples","content":"输入\n5\n1 3 2 5 4\n输出\n1 3 5 \n2 4 \n\n输入\n4\n4 3 2 1\n输出\n4 \n3 \n2 \n1 \n\n输入\n4\n10 30 50 101\n输出\n10 30 50 101 "}]}
**Definitions**
Let $ n \in \mathbb{Z}^+ $ be the number of elements.
Let $ A = (a_1, a_2, \dots, a_n) $ be a sequence of distinct integers.
**Constraints**
$ 1 \leq n \leq 2 \cdot 10^5 $,
$ 1 \leq a_i \leq 10^9 $ for all $ i \in \{1, \dots, n\} $,
All $ a_i $ are distinct.
**Objective**
Partition $ A $ into the minimum number of increasing subsequences, constructed greedily as follows:
- While $ A $ is non-empty:
- Extract the longest possible increasing subsequence starting from the leftmost unused element, by greedily including the next unused element that is greater than the last included element.
- Output each extracted subsequence on a separate line.
API Response (JSON)
{
"problem": {
"name": "B. Preparing for Merge Sort",
"description": {
"content": "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 increasin",
"description_type": "Markdown"
},
"platform": "Codeforces",
"limit": {
"time_limit": 2000,
"memory_limit": 262144
},
"difficulty": "None",
"is_remote": true,
"is_sync": true,
"sync_url": null,
"sign": "CF847B"
},
"statements": [
{
"statement_type": "Markdown",
"content": "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 increasin...",
"is_translate": false,
"language": "English"
},
{
"statement_type": "Markdown",
"content": "[{\"iden\":\"statement\",\"content\":\"Ivan 有一个包含 #cf_span[n] 个不同整数的数组。他决定将所有元素按升序重新排列。Ivan 喜欢归并排序,因此他打算将他的数组表示为一个或多个递增序列,然后将这些序列归并为一个有序数组。\\n\\nIvan 使用以下算法将他的数组表示为递增序列。\\n\\n当数组中至少还有一个未使用的数字时,Ivan 重复以下过程:\\n\\n例如...",
"is_translate": true,
"language": "Chinese"
},
{
"statement_type": "Markdown",
"content": "**Definitions** \nLet $ n \\in \\mathbb{Z}^+ $ be the number of elements. \nLet $ A = (a_1, a_2, \\dots, a_n) $ be a sequence of distinct integers.\n\n**Constraints** \n$ 1 \\leq n \\leq 2 \\cdot 10^5 $, \n$ ...",
"is_translate": false,
"language": "Formal"
}
]
}