#C1373. Subarray Reversal Sorting
Subarray Reversal Sorting
Subarray Reversal Sorting
You are given an array of integers. In a single operation, you are allowed to reverse any subarray of the array. There is no limit on the number of operations you can perform.
The inversion count of an array is defined as $$\text{inversions} = \#\{(i,j) \mid i a_j\}.$$ Your task is to determine the minimum number of inversions after you have performed a sequence of subarray reversals. Since you are allowed to reverse any subarray, you can always completely sort the array, thereby reducing the inversion count to 0 for any given array.
This problem tests your ability to understand that sometimes the optimal strategy makes the given computation trivial.
inputFormat
The first line contains an integer T representing the number of test cases. Each test case consists of two lines:
- The first line contains an integer n, the number of elements in the array.
- The second line contains n space-separated integers representing the array.
outputFormat
For each test case, output a single line containing the minimum number of inversions after sorting the array. Since it is always possible to sort the array completely using subarray reversals, the answer will always be 0
.
5
5
3 1 2 5 4
4
4 3 2 1
1
1
5
1 2 3 4 5
5
5 4 3 2 1
0
0
0
0
0
</p>