Paimon Sorting
Time limit1sMemory limit1024 MB
For each prefix of a sequence, count how many swaps the bubble-like Sort procedure performs on that prefix.
Problem
Paimon has just invented a new sorting algorithm that looks much like bubble sort, with a few differences. It accepts a 1-indexed sequence of length and sorts it. The pseudo-code is shown below.
Function 1: The Sorting Algorithm
1. function Sort(A)
2. for i ← 1 to n do // n is the number of elements in A
3. for j ← 1 to n do
4. if a_i < a_j then // a_i is the i-th element in A
5. Swap a_i and a_j
If you doubt that this algorithm can sort a sequence, prove it. That is part of the task.
Given an integer sequence of length , count the number of swaps performed for each prefix of length , where and . That is, count the swaps performed when you call SORT().
Input
There are multiple test cases. The first line contains an integer , the number of test cases. Each test case is given as follows.
The first line contains an integer (), the length of the sequence.
The second line contains integers (), the sequence.
The sum of over all test cases does not exceed .
Output
For each test case, output one line containing integers separated by spaces, where is the number of swaps performed when you call SORT().