#P1637H. Minimize Inversions Number
Minimize Inversions Number
Description
You are given a permutation of length .
You can choose any subsequence, remove it from the permutation, and insert it at the beginning of the permutation keeping the same order.
For every from to , find the minimal possible number of inversions in the permutation after you choose a subsequence of length exactly .
The first line contains a single integer () — the number of test cases.
The first line of each test case contains one integer () — the length of the permutation.
The second line of each test case contains the permutation ().
It is guaranteed that the total sum of doesn't exceed .
For each test case output integers. The -th of them must be the answer for the subsequence length of .
Input
The first line contains a single integer () — the number of test cases.
The first line of each test case contains one integer () — the length of the permutation.
The second line of each test case contains the permutation ().
It is guaranteed that the total sum of doesn't exceed .
Output
For each test case output integers. The -th of them must be the answer for the subsequence length of .
Note
In the second test case:
- For the length : : inversions.
- For the length : : inversions.
- For the length : , or : inversions.
- For the length : : inversion.
- For the length : : inversions.