atcoder#ARC124D. [ARC124D] Yet Another Sorting Problem
[ARC124D] Yet Another Sorting Problem
Score : points
Problem Statement
Given is a sequence of length , which is a permutation of . The -th term of is .
You can do the following Operation any number of times.
Operation: Choose an integer between and (inclusive), and an integer between and (inclusive). Then, swap and .
Find the minimum number of Operations needed to sort in ascending order. We can prove that it is possible to sort in ascending order under the Constraints of this problem.
Constraints
- All values in input are integers.
- is a permutation of .
Input
Input is given from Standard Input in the following format:
Output
Print the minimum number of Operations needed to sort in ascending order.
2 3
1 4 2 5 3
3
5 7
9 7 12 6 1 11 2 10 3 8 4 5
10