QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 1024 MB Puntuación total: 100

#13248. pm

Estadísticas

You are given a permutation $\{a_1, a_2, \dots, a_n\}$ of $\{1, 2, \dots, n\}$, and you need to transform it into $\{1, 2, \dots, n\}$.

You can perform operations in two stages. In the first stage, you can perform any number of operations, where each operation consists of choosing two adjacent elements and swapping them. In the second stage, you can perform any number of operations, where each operation consists of changing the value of an element at any position. In the second stage, you can modify elements arbitrarily; even if the sequence is no longer a permutation during the intermediate steps, it is still valid.

You need to minimize the total number of operations across both stages and provide a valid sequence of operations that achieves this minimum. For simplicity, you only need to output the operations for the first stage. The SPJ (Special Judge) will automatically calculate the optimal operations for the second stage and compare the total number of operations with the optimal total.

Input

The first line contains a positive integer $n$. The second line contains $n$ positive integers $a_1, a_2, \dots, a_n$.

Output

The first line outputs the number of operations $u$ in the first stage. The second line outputs $u$ space-separated positive integers $p_1, p_2, \dots, p_u$ ($1 \le p_i < n$), representing the sequence of swaps: $(a_{p_1}, a_{p_1+1}), (a_{p_2}, a_{p_2+1}), \dots, (a_{p_u}, a_{p_u+1})$.

Examples

Input 1

4
4 3 2 1

Output 1

1
2

Note

In the first stage, the two middle elements are swapped. In the second stage, the first and fourth elements are modified, requiring a total of 3 operations. It can be proven that this is optimal.

Subtasks

Subtask 1 (10pts): $n \le 5$. Subtask 2 (10pts): $n \le 9$. Subtask 3 (10pts): $n \le 50$. Subtask 4 (20pts): $n \le 500$. Subtask 5 (10pts): $n \le 2000$. Subtask 6 (20pts): $n \le 10^5$. Subtask 7 (20pts): $n \le 2 \times 10^5$.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.