Sort4官方中文
题目描述
官方中文Given a permutation$^\dagger$ of length $n$. In one operation, you can choose at most four elements from the permutation and swap their positions arbitrarily. What is the minimum number of operations required to sort the permutation in ascending order? $^\dagger$ A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array).官方中文
输入格式
官方中文Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \leq t \leq 10^5$). The description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \leq n \leq 10^6$), indicating the length of the permutation.
The second line contains a permutation $a_1, a_2, \ldots, a_n$.
It is guaranteed that the sum of $n$ across all test cases does not exceed $10^6$.官方中文
输出格式
官方中文For each test case, output a single integer, indicating the minimum number of operations required to sort the permutation.官方中文
样例
4
4
4 2 1 3
6
4 2 5 1 3 6
8
5 4 6 3 1 8 2 7
10
1 2 9 10 3 6 8 4 5 71
1
3
2题面与样例版权归 牛客竞赛 及出题人所有;中文翻译由 AI 生成(官方原文),如有出入请以原文为准。