#P9259. Fotografia Reordering
Fotografia Reordering
Fotografia Reordering
This problem is adapted from PA 2022 Round 3 Fotografia.
Bajtockiej Szkoły Technicznej (BST) graduates are standing in a row in front of their school. Their positions are numbered from 1 to n (from left to right), where n is the number of graduates. Each graduate has a unique height.
The photographer wishes to rearrange the students so that their heights are in ascending order (i.e. the shortest at the left and the tallest at the right). To avoid confusion, the rearrangement is performed via the following operation:
In one operation, the photographer calls out a sequence of positions. The graduates standing in these positions step out in the order they are called and stand temporarily in the middle of the square. Then, the photographer calls out the same sequence of positions again; this time, the graduates re-enter the row, but in the reverse order relative to the order in which they stepped out. In other words, if the professor calls out positions p1, p2, ..., pk, then the graduate originally at p1 will return last and the one from pk will return first among those positions.
Your task is to plan a sequence of operations so that after applying them the graduates are arranged in ascending order of height. For each operation you decide which positions to call out. Note that using an operation with exactly 2 positions will effectively swap the two graduates in those positions. There is no requirement that the chosen positions be consecutive.
Input/Output details: You are given the initial arrangement and you must output a valid sequence of operations that sorts the array.
The formulas in this problem are given in LaTeX format. For example, the positions are numbered from $1$ to $n$, and the operation is described for a sequence of positions $p_1, p_2, \dots, p_k$.
inputFormat
The input consists of two lines. The first line contains an integer $n$ ($1 \leq n \leq 10^5$), which is the number of graduates. The second line contains $n$ space-separated distinct integers representing the heights of the graduates in their initial order.
outputFormat
The output should begin with an integer $m$, the number of operations performed. Each of the next $m$ lines represents an operation. An operation is described by an integer $k$ (the number of positions in this operation) followed by $k$ space-separated integers, indicating the positions that will have their order reversed. (Note that using $k=2$ is equivalent to swapping the two graduates at those positions.)
sample
3
150 160 155
1
2 2 3
</p>