Paimon Sorting
시간 제한1초메모리 제한1024 MB
주어진 이중 반복 정렬 알고리즘이 각 접두사에 대해 수행하는 교환 횟수를 구한다.
문제
Paimon just invents a new sorting algorithm which looks much like bubble sort, with a few differences. It accepts a -indexed sequence of length and sorts it. Its pseudo-code is shown below.
Functions 1 The Sorting Algorithm
- function Sort()
- for ← to do // is the number of elements in
- for ← to do
- if then // is the -th element in
- Swap and
If you don't believe this piece of algorithm can sort a sequence it will also be your task to prove it. Anyway here comes the question:
Given an integer sequence of length , for each of its prefix of length (that is, for each , consider the subsequence ), count the number of swaps performed if we call .
입력
There are multiple test cases. The first line of the input contains an integer indicating the number of test cases. For each test case:
The first line contains an integer () indicating the length of the sequence.
The second line contains integers () indicating the given sequence.
It's guaranteed that the sum of of all test cases will not exceed .
출력
For each test case output one line containing integers separated by a space, where is the number of swaps performed if we call .