codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

847B.md (1969B)


      1 Source: https://codeforces.com/problemset/problem/847/B
      2 
      3 B. Preparing for Merge Sort
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23 Ivan represent his array with increasing sequences with help of the following algorithm.
     24 
     25 While there is at least one unused number in array Ivan repeats the following procedure:
     26 
     27 * iterate through array from the left to the right;
     28 * Ivan only looks at unused numbers on current iteration;
     29 * 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.
     30 
     31 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].
     32 
     33 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.
     34 
     35 Input
     36 
     37 The first line contains a single integer *n* (1 ≤ *n* ≤ 2·105) — the number of elements in Ivan's array.
     38 
     39 The second line contains a sequence consisting of distinct integers *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ 109) — Ivan's array.
     40 
     41 Output
     42 
     43 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.
     44 
     45 Examples
     46 
     47 Input
     48 
     49 ```
     50 5  
     51 1 3 2 5 4
     52 ```
     53 
     54 Output
     55 
     56 ```
     57 1 3 5   
     58 2 4
     59 ```
     60 
     61 Input
     62 
     63 ```
     64 4  
     65 4 3 2 1
     66 ```
     67 
     68 Output
     69 
     70 ```
     71 4   
     72 3   
     73 2   
     74 1
     75 ```
     76 
     77 Input
     78 
     79 ```
     80 4  
     81 10 30 50 101
     82 ```
     83 
     84 Output
     85 
     86 ```
     87 10 30 50 101
     88 ```