#P1896E. Permutation Sorting
Permutation Sorting
No submission language available for this problem.
Description
You are given a permutation of size . We call an index good if is satisfied. After each second, we rotate all indices that are not good to the right by one position. Formally,
- Let be the indices of that are not good in increasing order. That is, and if index is not good, then there exists such that .
- For each from to , we assign all at once.
For each from to , find the first time that index becomes good.
A permutation is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, but is not a permutation ( appears twice in the array) and is also not a permutation ( but there is in the array).
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer () — the size of permutation .
The second line of each test case contains integers () — the elements of permutation .
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, output a single line containing integers where the -th integer represents the first time that index becomes good.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer () — the size of permutation .
The second line of each test case contains integers () — the elements of permutation .
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output a single line containing integers where the -th integer represents the first time that index becomes good.
Note
In the first test case, and are already in the correct position so indices and become good at second. After second, a cyclic shift will be done with , resulting in array . Notice that indices , and become good at second.
In the second test case, is already in the correct position, so index becomes good at second. After second, a cyclic shift will be done with , resulting in array . Notice that indices , and become good at second. After seconds, a cyclic shift will be done with , resulting in array . Notice that indices and become good at second.