[Solution] Dearrange sorting Solution CodeChef Solution | CodeChef Problem Solution 2022
You are given a permutation of length . A permutation of length is an array where every element from to occurs exactly once.
You must perform some operations on the array to make it sorted in increasing order. In one operation, you must:
- Select two indices and
- Completely dearrange the subarray
A dearrangement of an array is any permutation of for
Solution Click Below:- CLICK HERE
which for all .
For example, consider the array . Some examples of dearrangements of are , and . is not a valid dearrangement since it is not a permutation of . is not a valid dearrangement either since and .
Find the minimum number of operations required to sort the array in increasing order. It is guaranteed that the given permutation can be sorted in atmost operations.
Input Format
- The first line contains a single integer — the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer — the size of the permutation .
- The second line of each test case contains space-separated integers denoting the permutation .
Output Format
- On the first line of each test case output the minimum number of operations . The description of the operations must follow.
- Each operation must be described in two lines
- On the first line of each operation output two space separated integers and — the indices of the subarray chosen.
- On the second line output space separated integers — the permutation after dearranging the subarray . Note that you have to output the whole permutation
Constraints
- is a permutation of length
- The sum of over all test cases does not exceed
- It is guaranteed that the given permutations can be sorted in atmost operations.
No comments:
Post a Comment