#P7128. 「RdOI R1」序列(sequence)

「RdOI R1」序列(sequence)

Description

There is a sequence xx of length qq, and each number in the sequence appears exactly once.

That is, the sequence xx is a permutation of 11 to qq.

There is only one allowed operation on sequence xx: for a number xix_i, you may swap it with x2ix_{2i} or x2i+1x_{2i+1} (if they exist).

Now, please turn sequence xx into an increasing sequence, and output the operations you perform in order.

Input Format

The input has a total of 22 lines.

Line 11 contains 11 positive integer qq.

Line 22 contains qq positive integers, x1qx_{1~q}.

Output Format

The output has a total of ansans lines, where ansans is the number of operations you perform.

Lines 11 to ansans each contain two integers ii, jj, meaning to swap the positions of xix_i and xjx_j (i<j)(i < j).

3
3 1 2
1 3
1 2
7
1 3 2 7 6 4 5
2 4
1 2
1 3
3 7
2 5
1 2
1 3
3 6
1 2
2 5
1 3
1 2
2 4
1 2
1 3
1 2

Hint

[Sample Explanation]

Explanation of Sample #1:

Swap 22 and 33, and the sequence becomes: 2,1,32,1,3.

Then swap 22 and 11, and the sequence becomes: 1,2,31,2,3.

[Constraints]

For 40%40\% of the testdata, 3q2103 \le q \le 2^{10}.

For 100%100\% of the testdata, 3q2173 \le q \le 2^{17}, 1xiq1 \le x_i \le q.

[Hint]

  • Use Special Judge.
  • q=2p1(pN)q = 2 ^ p - 1(p \in \mathbb{N}^*).
  • Perform at most 2q×log2q2q\times\lceil\log_2 q\rceil operations.
  • The sample output is just one of many possible solutions.
  • Because it is special judge, no additional samples are provided.

[File Input/Output] (Simulation, not needed when submitting code)

  • File name: sequence.cpp.
  • Input file name: sequence.in.
  • Output file name: sequence.out.

Translated by ChatGPT 5