#P10155. [LSOT-2] 基于二分查找与插入的快速排序
[LSOT-2] 基于二分查找与插入的快速排序
Background
Little H cannot sort, but he can do binary search.
So he created a quicksort based on binary search and insertion.
This problem has a solution that supports modifications, but since this is the check-in problem of this contest, the kind problem setter did not add it.
Problem Description
Given a permutation . Each time, you may choose a number . You need to find the smallest such that and , and insert before . You need to minimize the number of operations needed to make .
If no such exists, then you cannot perform an operation.
Input Format
The first line contains an integer , representing the length of the permutation.
The next line contains integers describing the permutation , where the -th number is .
Output Format
Output one integer on a single line, representing the minimum number of operations. If it is impossible to finish sorting, output .
5
3 1 4 2 5
2
Hint
"This problem uses bundled tests."
- .
- guarantee .
- .
- no special properties.
For all testdata, , and is a permutation of to .
Translated by ChatGPT 5