logo AlgoBeat OnlineJudge
登录 注册

#215997. [TOPC 2021] A Sorting Problem

内存限制:512 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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:

  1. Swap and . The array becomes .
  2. 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.

样例

样例输入 1

3
1 3 2

样例输出 1

1

样例输入 2

5
5 3 2 1 4

样例输出 2

7

数据范围与提示

  • .
  • .
  • All are distinct.