#P7714. 「EZEC-10」排列排序
「EZEC-10」排列排序
Description
You are given a permutation of length . You need to sort it.
Each time, you may pay a cost equal to the length of the interval, i.e. , choose any interval in the permutation, and sort in increasing order.
Now you can perform this operation several times until the values in are sorted in increasing order from to , that is, for every from to , we have .
What is the minimum total cost?
Input Format
This problem has multiple test cases. The first line contains an integer , indicating the number of test cases.
For each test case:
The first line contains an integer .
The second line contains integers separated by spaces, representing the values of the permutation .
Output Format
Output lines, each containing one integer representing the answer for one test case.
2
3
1 3 2
4
3 2 1 4
2
3
Hint
[Sample Explanation]
For the first test case, you can choose the interval to sort.
For the second test case, you can choose the interval to sort.
[Constraints]
For of the testdata, .
For another of the testdata, .
For another of the testdata, .
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号