JPMorgan ChaseOA #33
Minimum Swaps
估计中等可在线判题
The potentials are distinct, and each operation may swap any two positions. Find the minimum number of operations to make the array descending. Being distinct with values in 1..n means the input is a permutation of 1..n.
输入格式
The first line contains n, and the second line contains the permutation; full original bounds 1≤n≤200000, 1≤a[i]≤n, all distinct.
输出格式
Output a single integer answer.
样例 1
输入:
4
3 4 1 2
输出:
2
样例 2
输入:
1
1
输出:
0
样例 3
输入:
3
1 2 3
输出:
1
样例说明
The outputs of the three public examples are, in order: 2; 0; 1. These answers have been checked by independent enumeration or direct simulation.