#P16027. [CSPro 23] 非零段划分
[CSPro 23] 非零段划分
Background
Luogu’s testdata are only for community exchange and are not official testdata. Official judging link: https://www.cspro.org/.
Problem Description
is an array of natural numbers (non-negative integers). We call a non-zero segment if and only if all of the following conditions are satisfied at the same time:
- ;
- For any integer , if , then ;
- or ;
- or .
Some simple examples are shown below:
- In , the 4 non-zero segments are , , , and in order;
- has only 1 non-zero segment;
- contains no non-zero segments (i.e., the number of non-zero segments is ).
Now we can perform the following operation on array : choose any positive integer , and then change all numbers in that are less than into . Try to choose a suitable so that the number of non-zero segments in is maximized. If the number of non-zero segments in the input has already reached the maximum possible value, you may take , meaning no modification is made to .
Input Format
Read input from standard input.
The first line contains a positive integer .
The second line contains natural numbers , separated by spaces.
Output Format
Write output to standard output.
Output only one integer, which is the maximum number of non-zero segments that can be achieved after performing the operation on array .
11
3 1 2 0 0 2 0 4 5 0 2
5
14
5 1 20 10 10 10 10 15 10 20 1 5 10 15
4
3
1 0 0
1
3
0 0 0
0
Hint
Explanation for Sample 1
When , . The 5 non-zero segments are , , , , and in order. At this time, the number of non-zero segments is maximized.
Explanation for Sample 2
When , . The 4 non-zero segments are , , , and in order. At this time, the number of non-zero segments is maximized.
Explanation for Sample 3
When , . At this time, there is only 1 non-zero segment , and the number of non-zero segments is maximized.
Explanation for Sample 4
No matter what value takes, contains no non-zero segments, so the number of non-zero segments can be at most .
Subtasks
of the testdata satisfy .
All testdata satisfy , and every number in array is at most .
Translated by ChatGPT 5