#P15442. [蓝桥杯 2025 国研究生组] 山峰子序列

    ID: 17465 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度提高 上传者: 标签>动态规划 DP树状数组2025动态规划优化蓝桥杯国赛

[蓝桥杯 2025 国研究生组] 山峰子序列

Background

C/C++/Python Postgraduate Group.

Problem Description

A sequence T=[t1,t2,,tk]T = [t_1, t_2, \cdots, t_k] is a “mountain peak sequence” if and only if there exists an index-pair sequence of length mm (mm can be chosen arbitrarily), (l1,r1),(l2,r2),,(lm,rm)(l_1, r_1), (l_2, r_2), \cdots, (l_m, r_m), such that:

  • l1=1l_1 = 1 and rm=kr_m = k.
  • ri>lir_i > l_i.
  • ri1+1=lir_{i-1} + 1 = l_i.
  • rili0(mod2)r_i - l_i \equiv 0 \pmod{2} and t(li+ri)/2t_{(l_i + r_i)/2} is the maximum value of sequence TT on the interval [li,ri][l_i, r_i].
  • Sequence TT is strictly increasing on the interval [li,li+ri2][l_i, \dfrac{l_i + r_i}{2}], and strictly decreasing on the interval [li+ri2,ri][\dfrac{l_i + r_i}{2}, r_i].

Given an integer array of length nn, [a1,a2,,an][a_1, a_2, \cdots, a_n], find the longest subsequence TT such that TT is a “mountain peak sequence”, and output its length.

Note: The index-pair sequence (li,ri)(l_i, r_i) is based on the indices of the subsequence TT, and the indices of TT start from 1.

Input Format

The first line contains a positive integer nn.

The second line contains nn integers a1,a2,,ana_1, a_2, \cdots, a_n, separated by one space.

Output Format

Output one line containing one integer, which is the answer.

10
1 3 2 4 1 2 3 4 3 1
8

Hint

Sample Explanation

You can take the subsequence T=[1,3,2,1,2,4,3,1]T = [1, 3, 2, 1, 2, 4, 3, 1]. Its length is 8 and it is a “mountain peak sequence”. The index-pair sequence is (1,3),(4,8)(1, 3), (4, 8).

Test Case Scale and Conventions

For 20%20\% of the test cases, 1n501 \le n \le 50.

For 40%40\% of the test cases, 1n2001 \le n \le 200.

For all test cases, 1n20001 \le n \le 2000, 0ai1060 \le a_i \le 10^6.

Input Format

Output Format

Translated by ChatGPT 5