#P9290. [ROI 2018] Decryption
[ROI 2018] Decryption
Background
Translated from ROI 2018 Day2 T1. Расшифровка (Decryption).
Problem Description
Research shows that the order of Chinese characters does not necessarily affect reading. Scientists have done similar research on sequences.
Given a positive integer sequence, if the first element is the minimum among all numbers in the sequence, and the last element is the maximum among all numbers in the sequence, then we call it a correct sequence. For example, the sequences and are correct, but the sequence is not.
You are given a sequence of length : . For a segment of this sequence , if the first element of the segment is the minimum within the segment, and the last element of the segment is the maximum within the segment, then we call it a correct segment.
For the given sequence, find the minimum number of segments it must be split into so that every segment is a correct segment. The sequence can be split into three correct segments: , , and .
Write a program that, in the given order, determines the minimum number of correct segments.
Input Format
The first line contains an integer .
The next line contains numbers: .
Output Format
Output the minimum number of segments that the sequence can be split into.
5
5 4 3 2 1
5
4
1 3 2 4
1
6
2 3 1 1 5 1
3
Hint
- Subtask 1 (30 points): .
- Subtask 2 (30 points): .
- Subtask 3 (40 points): .
Constraints: For all testdata, , and .
Translated by ChatGPT 5