You are given a permutation of size N. You want to sort it. In one operation you can…
- User
You are given a permutation of size N. You want to sort it. In one operation you can swap the ith and the jth elements (1 ≤ i, j ≤ N) and it will cost you i&j (bitwise AND of i and j). Total sum of sorting the permutation is the sum of the cost of all the operations you will make. You can’t make more than 3*N operations. Print the minimum cost to sort the permutation and also print one sequence of swap operations which will sort the permutation in the minimum cost. Input The first line will contain a single integer T (1 ≤ T ≤ 10^4). Each test case will start with one integer N (1 ≤ N ≤ 104), the length of the permutation. The next line will contain N integers a1, a2, …. , aN (1 ≤ ai ≤ N). It is guaranteed that, in any input file ΣN ≤ 10^5 across all the test cases. Input file is large. Please be sure to use faster input/output methods.
solve using c++
- Assistant