PivotOJ

Incomplete Sort

시간 제한: 2000ms메모리 제한: 512MB출처: BAPC 2020BOJ 20337

문제

Merge sort is a sorting algorithm. It works by splitting an array in half, sorting both halves recursively and then merging those halves together to sort the entire array. Your friend is working on an implementation of the merge sort algorithm, but unfortunately he is not quite there yet: he can only sort half of the array! In great despair he turns to you for help: can you use his unfinished code to write an algorithm that sorts an array completely?

In its current state, your friend's code is a sorting function that can be run on arbitrary sub-arrays, as long as it is precisely half as long as the original array. It then correctly sorts this sub-array. You decide to play around with this function, so you start with a jumbled array and try to sort it (see figure). After choosing 33 sub-arrays and using them as input for the sorting function, you end up with a sorted array. Interestingly, it seems that no matter what the original array you use is, you can always sort it completely by invoking your friend's sorting function only 33 times. You decide that this makes for a good challenge: you want to extend the code to work for a full array, making at most three calls to the sorting function.

Now you need to figure out which sub-arrays to sort! Given an array of length nn, output at most three sub-arrays of length 12n\tfrac{1}{2}n so that sorting these sub-arrays in order will result in a sorted array. It is guaranteed that this is always possible.

Figure I.1: First sorting step of sample output 1

입력

  • One line containing a single integer nn (4n1054\leq n\leq 10^5) divisible by 44, the length of the array.
  • One line containing nn unique integers aa (1an1\leq a \leq n), the array to be sorted.

출력

The output consists of:

  • One line containing the number of function calls ff (0f30\leq f \leq 3).
  • ff lines, each containing 12n\tfrac{1}{2}n unique integers ii (1in1\leq i \leq n), the indices determining the sub-array to be sorted at each of the function calls.

If there are multiple valid solutions, you may output any one of them. You do not have to minimise ff.

예제

예제 1

입력
8
3 8 4 7 1 5 2 6
출력
3
2 3 6 8
1 3 4 5
2 4 5 7

예제 2

입력
4
1 4 3 2
출력
3
3 4
2 3
3 4

예제 3

입력
8
1 4 8 7 5 6 3 2
출력
2
3 5 6 8
2 3 4 7
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.