#P11079. 「FSLOI Round I」山峦

    ID: 10449 远端评测题 500ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP洛谷原创O2优化洛谷月赛

「FSLOI Round I」山峦

Description

An integer sequence aa of length m(m3)m(m \ge 3) is called a peak if and only if it satisfies the following condition:

  • There exists an integer x(2xm1)x(2 \le x \le m-1) where a1<a2<<ax>ax+1>>ama_1<a_2<\dots<a_x>a_{x+1}>\dots>a_m. We call axa_x as the height of the peak.

An integer sequence bb is called a mountain if and only if it satisfies one of the following conditions:

  • bb is a peak.

  • bb can be split into at least two continuous subsequences, where each subsequence is a peak and the heights of the peaks are strictly increasing from left to right.

For example, the sequence {2,4,3,1,5,2,1}\{2,4,3,1,5,2,1\} is a mountain, because it can be split into two peaks: {2,4,3}\{2,4,3\} and {1,5,2,1}\{1,5,2,1\}, and the heights of the peaks ({4,5})(\{4,5\}) are strictly increasing. {2,4,3,5,2,1}\{2,4,3,5,2,1\} is not a peak because it itself isn't a peak and it cannot be split into multiple peaks.

You are given a sequence aa of length nn. You need to find out the number of mountains among all the subsequences of aa.

The answer may be very large, so please print the answer modulo 998,244,353998{,}244{,}353.

Note that, for two subsequences s={ai1,ai2,,aip}s=\{a_{i_1},a_{i_2},\dots,a_{i_p}\} and t={aj1,aj2,,ajq}t=\{a_{j_1},a_{j_2},\dots,a_{j_q}\}, they are different if and only if {i1,i2,,ip}{j1,j2,,jq}\{i_1,i_2,\dots,i_p\}\neq\{j_1,j_2,\dots,j_q\}. In other words, even if two subsequences have the same elements, they are distinguished as long as the positions of the elements are different.

Input Format

The first line of the input contains a single integer nn representing the length of the given sequence.

The second line contains nn integers a1,a2,,ana_1,a_2,\dots,a_n, representing the sequence aa.

Output Format

Output a single integer, representing the answer modulo 998,244,353998{,}244{,}353.

4
1 2 2 1
2
7
2 4 3 1 5 2 1
35
20
2 3 5 6 8 7 6 5 6 7 8 8 8 8 4 3 5 6 7 4
15085

Hint

Example Explanation

In the first example, {a1,a2,a4}\{a_1,a_2,a_4\} and {a1,a3,a4}\{a_1,a_3,a_4\} are mountains.

Constraints

Subtasks are used in this problem.

For all tests, it is guaranteed that:

  • 1n5001 \leq n \leq 500
  • 1ai1061 \leq a_i \leq 10^6
Subtask Id Score Special Property
11 1010 n18n \leq 18
22 1515 n80n \leq 80
33 AA
44 2020 BB
55 4040 -

Special Property AA: aa is a peak.

Special Property BB: a1,a2,,ana_1,a_2,\dots,a_n are pairwise distinct.