#DSU0000053. Sắp xếp bằng các dãy con (Sorting by Subsequences)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Sắp xếp bằng các dãy con (Sorting by Subsequences)
Sorting by Subsequences
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array of pairwise distinct integers. Partition the entire set of indices into nonempty groups, with every index belonging to exactly one group.
For each group, take the values currently stored at its indices and sort those values in increasing order, placing them back at the group's indices in increasing index order. Groups are disjoint, so they may be processed in any order. After every group is sorted, the whole array must be increasing.
Find a valid partition with the maximum possible number of groups. Print the number of groups and their index lists. If several optimal partitions exist, you may output any of them.
Input
The first line contains , then pairwise distinct integers with .
Output
Print the number of subsequences, then one line per subsequence containing its size and its indices (1-based). Every index must appear exactly once; any optimal answer is accepted.
Subtasks
- Subtask 1 (20 points): ; ; the values are pairwise distinct.
- Subtask 2 (30 points): ; ; the values are pairwise distinct.
- Subtask 3 (50 points): ; ; the values are pairwise distinct.
Examples
Input
6
3 2 1 6 5 4
Output
4
2 1 3
1 2
2 4 6
1 5
Explanation
Sorting positions and gives . The two singleton groups leave the array unchanged. Four is the largest possible number of groups.