CF843A.Sorting by Subsequences

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

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.

Every element of the sequence must appear in exactly one subsequence.

给你一个由互不相同的整数构成的序列 a1, a2, ..., ana_1,\,a_2,\,...,\,a_n。要求将该序列划分为尽可能多的子序列,使得对每个子序列内的整数按升序排序后,整个序列也变为升序排列。

对子序列中的整数进行排序,是指仅将属于该子序列的数字按升序重新排列,而未被包含在该子序列中的数字位置保持不变。

序列中的每个元素必须且只能出现在一个子序列中。

输入格式

The first line of input data contains integer n (1 ≤ n ≤ 105) — the length of the sequence.

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.

输入数据的第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)—— 序列的长度。

输入数据的第二行包含 nn 个互不相同的整数 a1,a2,…,ana_1, a_2, \dots, a_n(−109≤ai≤109-10^9 \leq a_i \leq 10^9)—— 序列的元素。保证序列中所有元素互不相同。

输出格式

In the first line print the maximum number of subsequences k, which the original sequence can be split into while fulfilling the requirements.

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.

Indices could be printed in any order. Every index from 1 to n must appear in output exactly once.

If there are several possible answers, print any of them.

第一行输出最大子序列个数 kk,即原序列在满足题目要求的前提下可被划分出的子序列的最大数目。

接下来 kk 行,每行描述一个子序列,格式如下:先输出该子序列的元素个数 cic_i(其中 0<ci≤n0 < c_i \leq n),然后输出 cic_i 个整数 l1, l2, …, lcil_1,\ l_2,\ \dots,\ l_{c_i}(其中 1≤lj≤n1 \leq l_j \leq n),表示这些元素在原序列中的下标。

下标可以以任意顺序输出。从 11 到 nn 的每个下标在输出中必须恰好出现一次。

若存在多种可行解,输出任意一种即可。

输入输出样例

  • 输入#1

    6
    3 2 1 6 5 4

    输出#1

    4
    2 1 3
    1 2
    2 4 6
    1 5
  • 输入#2

    6
    83 -75 -49 11 37 62

    输出#2

    1
    6 1 2 3 4 5 6

说明/提示

In the first sample output:

After sorting the first subsequence we will get sequence 1 2 3 6 5 4.

Sorting the second subsequence changes nothing.

After sorting the third subsequence we will get sequence 1 2 3 4 5 6.

Sorting the last subsequence changes nothing.

在第一个样例输出中:

对第一个子序列排序后,得到序列 1 2 3 6 5 4。

对第二个子序列排序不改变任何元素。

对第三个子序列排序后,得到序列 1 2 3 4 5 6。

对最后一个子序列排序不改变任何元素。

输入解题思路,AI测评打分。不知道怎么写?

首页