Sort

AtCoder
IDabc350_c
Time2000ms
Memory256MB
Difficulty
You are given a permutation $A=(A_1,\ldots,A_N)$ of $(1,2,\ldots,N)$. Transform $A$ into $(1,2,\ldots,N)$ by performing the following operation between $0$ and $N-1$ times, inclusive: * Operation: Choose any pair of integers $(i,j)$ such that $1\leq i < j \leq N$. Swap the elements at the $i$\-th and $j$\-th positions of $A$. It can be proved that under the given constraints, it is always possible to transform $A$ into $(1,2,\ldots,N)$. ## Constraints * $2 \leq N \leq 2\times 10^5$ * $(A_1,\ldots,A_N)$ is a permutation of $(1,2,\ldots,N)$. * All input values are integers. ## Input The input is given from Standard Input in the following format: $N$ $A_1$ $\ldots$ $A_N$ [samples]
Samples
Input #1
5
3 4 1 2 5
Output #1
2
1 3
2 4

The operations change the sequence as follows:

*   Initially, $A=(3,4,1,2,5)$.
*   The first operation swaps the first and third elements, making $A=(1,4,3,2,5)$.
*   The second operation swaps the second and fourth elements, making $A=(1,2,3,4,5)$.

Other outputs such as the following are also considered correct:

4
2 3
3 4
1 2
2 3
Input #2
4
1 2 3 4
Output #2
0
Input #3
3
3 1 2
Output #3
2
1 2
2 3
API Response (JSON)
{
  "problem": {
    "name": "Sort",
    "description": {
      "content": "You are given a permutation $A=(A_1,\\ldots,A_N)$ of $(1,2,\\ldots,N)$.   Transform $A$ into $(1,2,\\ldots,N)$ by performing the following operation between $0$ and $N-1$ times, inclusive: *   Operation",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc350_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a permutation $A=(A_1,\\ldots,A_N)$ of $(1,2,\\ldots,N)$.  \nTransform $A$ into $(1,2,\\ldots,N)$ by performing the following operation between $0$ and $N-1$ times, inclusive:\n\n*   Operation...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments