codeforces-scrape

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

843A.md (2199B)


      1 Source: https://codeforces.com/problemset/problem/843/A
      2 
      3 A. Sorting by Subsequences
      4 
      5 time limit per test
      6 
      7 1 second
      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 You are given a sequence *a*1, *a*2, ..., *a**n* consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequence also will be sorted in increasing order.
     22 
     23 Sorting integers in a subsequence is a process such that the numbers included in a subsequence are ordered in increasing order, and the numbers which are not included in a subsequence don't change their places.
     24 
     25 Every element of the sequence must appear in exactly one subsequence.
     26 
     27 Input
     28 
     29 The first line of input data contains integer *n* (1 ≤ *n* ≤ 105) — the length of the sequence.
     30 
     31 The second line of input data contains *n* different integers *a*1, *a*2, ..., *a**n* ( - 109 ≤ *a**i* ≤ 109) — the elements of the sequence. It is guaranteed that all elements of the sequence are distinct.
     32 
     33 Output
     34 
     35 In the first line print the maximum number of subsequences *k*, which the original sequence can be split into while fulfilling the requirements.
     36 
     37 In the next *k* lines print the description of subsequences in the following format: the number of elements in subsequence *c**i* (0 < *c**i* ≤ *n*), then *c**i* integers *l*1, *l*2, ..., *l**c**i* (1 ≤ *l**j* ≤ *n*) — indices of these elements in the original sequence.
     38 
     39 Indices could be printed in any order. Every index from 1 to *n* must appear in output exactly once.
     40 
     41 If there are several possible answers, print any of them.
     42 
     43 Examples
     44 
     45 Input
     46 
     47 ```
     48 6  
     49 3 2 1 6 5 4
     50 ```
     51 
     52 Output
     53 
     54 ```
     55 4  
     56 2 1 3  
     57 1 2  
     58 2 4 6  
     59 1 5
     60 ```
     61 
     62 Input
     63 
     64 ```
     65 6  
     66 83 -75 -49 11 37 62
     67 ```
     68 
     69 Output
     70 
     71 ```
     72 1  
     73 6 1 2 3 4 5 6
     74 ```
     75 
     76 Note
     77 
     78 In the first sample output:
     79 
     80 After sorting the first subsequence we will get sequence 1 2 3 6 5 4.
     81 
     82 Sorting the second subsequence changes nothing.
     83 
     84 After sorting the third subsequence we will get sequence 1 2 3 4 5 6.
     85 
     86 Sorting the last subsequence changes nothing.