#P9771. [HUSTFC 2023] 排列排序问题
[HUSTFC 2023] 排列排序问题
Problem Description
JokerShaco has a permutation of length . He believes a permutation must be ordered, so he plans to sort it.
He can perform the following operations on this permutation:
- Cut the permutation into several sequences (or do not cut it and keep it as is). Each sequence must contain at least one element.
- Choose some of these sequences and reverse them.
- Recombine and concatenate these sequences in any order he wants to obtain a new permutation.
JokerShaco thinks the cutting operation is very tiring. He wants to know: if the permutation must be made ordered, what is the minimum number of cuts required.
A permutation of length is defined as a sequence containing distinct integers from to , where each integer appears exactly once.
The definition of reversing a sequence is: suppose there is a sequence of length , . After reversing it, it becomes .
Input Format
The first line contains an integer , representing the length of the permutation .
The second line contains integers, where the -th integer is defined as . It is guaranteed that the input is a permutation of length .
Output Format
Output one integer, representing the minimum number of cuts needed to make the permutation ordered.
5
1 2 3 5 4
1
3
3 2 1
0
Hint
Translated by ChatGPT 5