#P9673. [ICPC 2022 Jinan R] Quick Sort
[ICPC 2022 Jinan R] Quick Sort
题目描述
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 .
题目大意
题目描述
给定一个长度为 的排列 。现使用如下伪代码对 进行排序:
试计算:调用 QUICKSORT(A,1,n)
函数过程中,Swap
操作执行了多少次。
输入格式
第一行包含一个整数 ,表示测试数据组数。
对于每组测试数据:
第一行包含一个正整数 。
第二行包含 个整数 ,表示排列 。保证 构成一个排列,即:。
保证所有测试数据中 的和不超过 。
输出格式
对于每组测试数据,输出一行一个整数,表示调用 QUICKSORT(A,1,n)
函数过程中,Swap
操作执行的次数。