CF1662E.Round Table
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Each test contains multiple test cases. The first line contains an integer t ( 1≤t≤10000 ) — the number of test cases. The descriptions of the t test cases follow.
The first line of each test case contains a single integer n ( 3≤n≤200000 ) — the number of people sitting at the table.
The second line contains n distinct integers p1,p2,…,pn ( 1≤pi≤n , pi=pj for i=j ) — the desired final order of the people around the table.
The sum of the values of n over all test cases does not exceed 200000 .
输入格式
For each test case, print the minimum number of swaps necessary to achieve the desired order.
输出格式
In the first test case, we can swap person 4 and person 1 (who are adjacent) in the initial configuration and get the order [4,2,3,1] which is equivalent to the desired one. Hence in this case a single swap is sufficient.
输入输出样例
输入#1
3 4 2 3 1 4 5 5 4 3 2 1 7 4 1 6 5 3 7 2
输出#1
1 10 22
说明/提示
In the first test case, we can swap person 4 and person 1 (who are adjacent) in the initial configuration and get the order [4,2,3,1] which is equivalent to the desired one. Hence in this case a single swap is sufficient.