AIM Tech Round 4 (Div. 1)
A
Sorting by Subsequences
Codeforces
1400
原题
←B →
翻译中…

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.

翻译中…

Input

翻译中…

The first line of input data contains integer $*n*$ ($1 ≤ *n* ≤ 10^{5}$) — the length of the sequence.

翻译中…

The second line of input data contains $*n*$ different integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ ($- 10^{9} ≤ *a*_{*i*} ≤ 10^{9}$) — the elements of the sequence. It is guaranteed that all elements of the sequence are distinct.

翻译中…

Output

翻译中…

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.

翻译中…

Note

翻译中…

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.

翻译中…

样例

Input #1
6
3 2 1 6 5 4
Output #1
4
2 1 3
1 2
2 4 6
1 5
InputCopy OutputCopy
Input #2
6
83 -75 -49 11 37 62
Output #2
1
6 1 2 3 4 5 6
InputCopy OutputCopy
题目信息
题号
843A
时间限制
1 s
内存限制
256 MB
标签
DFS 及类似
并查集
模拟
数学
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。