#P15931. [TOPC 2021] A Sorting Problem
[TOPC 2021] A Sorting Problem
题目描述
You are given an array where all the numbers in the array are distinct. In addition, the numbers are positive integers between 1 and . You can only perform the following operations on the array: Pick two indices and such that , and then swap the values of and . We now want to sort this array in ascending order. That is, to make for all . For example, we can sort the array in two operations:
- Swap and . The array becomes .
- Swap and . The array becomes which is sorted in ascending order.
Please write a program to compute the minimum number of operations to sort a given array in ascending order.
输入格式
The input contain two lines. The first line contains one integer . The second lines contain space-separated numbers representing the array
输出格式
Output only one number that denotes the minimum number of operations required to sort the given array.
3
1 3 2
1
5
5 3 2 1 4
7
提示
- .
- .
- All are distinct.