#P11106. [ROI 2023] 峰值 (Day 1)
[ROI 2023] 峰值 (Day 1)
Background
Translated from ROI 2023 D1T3。
If for all , we have , then is called a peak.
If for all , we have , then is called an anti-peak.
Problem Description
You are given a permutation of size . You need to split it into two non-empty subsequences and . Each element of must be assigned to exactly one subsequence. You need to maximize the sum of the number of peaks in and the number of anti-peaks in .
Input Format
Each test consists of multiple test cases. The first line contains an integer , the number of test cases. The next lines describe the test cases, with each test case given in two lines.
The first line of each test case contains an integer , the size of the permutation.
The second line of each input test case contains integers , the original permutation. It is guaranteed that each number appears exactly once in .
The sum of over all test cases does not exceed .
Output Format
For each test case, output one integer: the maximum possible value of the number of peaks in plus the number of anti-peaks in after splitting .
4
5
4 1 2 3 5
10
3 8 10 4 1 2 7 9 5 6
3
1 2 3
6
4 2 5 1 6 3
5
6
3
5
Hint
Explanation of the first two samples:

Let .
| Subtask | Score | Special Properties | |
|---|---|---|---|
| The length of the longest decreasing subsequence of is at most | |||
Translated by ChatGPT 5