시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB7000.000%

문제

The cat Motanel’s favourite activity is sorting. She generally has a row of N blocks in front of her, of distinct sizes, and she tries to sort these in increasing order of size, by using a sequence of swaps. Since cat’s like pairing things, N is even. Unfortunately, the dastardly rat Sobo, tries to trick Motanel, and, each time Motanel swaps the ith block and the jth block, Sobo will then swap the blocks on positions (N-i+1) and (N-j+1). How can Motanel optimally sort the blocks ?

More formally, you are given a permutation P1, P2 … , PN. An operation on indices (i,j) is defined to swap Pi and Pj, and then to swap PN-i+1 and PN-j+1.

Given N and P, create a minimal sequence of operations that sorts P.

입력

There will be multiple test cases in each input file.

On the first line of the input there will be an integer that represents the number of test cases in this file. On the first line of each test case there will be an integer that represents the value of N.

On the next line of each test case will follow N integers, that represent P1, P2 … , PN respectively.

출력

Output the answers to the T test cases in order.

If there is no way of sorting the permutation, simply print -1 on a new line. Otherwise, begin by outputting a line that contains two integers g and L, which represent the length that you think a minimal sequence of operations has, and the length that your sequence of operations has (for partial points, these can be different). Then continue by outputting L further lines, each of which will contain two integers i and j. Such a line represents an operation on indices (i,j). Note you may choose to let L = 0 if you don’t aim at scoring the reconstruction points, for more details see section Scoring. You’ll get 0 points on the subtask of a test if you ever print a negative L, or make an invalid move. An invalid move (i,j) either has i = j or one of the positions out of the range [1, N]

제한

In all tests, 2 ≤ N ≤ 200000, N is even and P is a permutation: any value between 1 and N appears exactly once in P.

점수

Each subtask will be scored independently. The score you’ll get is the score assigned to the subtask multiplied with the minimum ratio among all tests of that subtask. The ratio of a test is computed as follows:

  • If there is any subtest where you haven’t properly decided whether a solution exists or not, then the ratio is 0
  • If you’ve made throughout the whole test more than 3 × 106 moves, the ratio is 0
  • If you’ve given a correct optimal reconstruction of moves for all subtests inside the test, the ratio for that test is 1.0 (regardless of whether your guess of optimal length was correct)
  • If you’ve computed the correct optimal number of moves and gave a correct, solution for all subtests inside the test, the ratio for that test is 0.7
  • If you’ve computed the correct optimal number of moves, the ratio is 0.4
  • If you’ve given a correct reconstruction of moves for every subtest that was solvable, the ratio is 0.35
  • If you have at least one wrong reconstruction for a subtest, provided you’ve correctly distinguished between when you can sort the permutation and when you can’t, the ratio for the test is 0.15

Assume these criteria are considered in this exact order and the coefficient is given by the first condition that matches the case of the current test.

서브태스크

번호배점제한
115

T ≤ 4000 and N ≤ 10

210

T ≤ 104 and sum of N2 over all tests ≤ 107 and Pi ≤ N/2 for any 1 ≤ i ≤ N/2

325

T ≤ 104 and sum of N2 over all tests ≤ 107

415

T ≤ 104 and sum of N over all tests ≤ 3×106 and Pi ≤ N/2 for any 1 ≤ i ≤ N/2

535

T ≤ 104 and sum of N over all tests ≤ 3×106

예제 입력 1

4
6
2 6 4 3 1 5
10
4 9 6 3 1 10 8 5 2 7
4
4 1 3 2
10
7 8 9 10 5 6 1 2 3 4

예제 출력 1

3 3
2 4
2 3
1 2
5 5
2 8
2 5
1 4
1 3
1 2
-1
2 2
2 8
1 7

채점 및 기타 정보

  • 예제는 채점하지 않는다.