logo AlgoBeat OnlineJudge
登录 注册

#209257. [ICPC 2022 Jinan R] Quick Sort

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

题目描述

When Prof. Pang was young, he wrote the following code for quick sort. Please calculate how many swaps are performed when calling . is a given permutation with length .

输入格式

The first line contains one integer , the number of test cases.

For each test case, the first line contains one positive integer . The next line contains integers denoting the permutation . It is guaranteed that form a permutation, i.e.~ for .

It is guaranteed that the sum of over all test cases is no more than .

输出格式

For each test case, output one line containing the number of swaps performed when calling .

样例

样例输入 1

3
3
3 2 1
5
2 4 5 3 1
10
7 2 4 6 1 9 10 8 5 3

样例输出 1

1
4
7