#P13550. 宇宙分解

    ID: 11832 远端评测题 1000ms 512MiB 尝试: 1 已通过: 1 难度: 6 上传者: 标签>洛谷原创O2优化组合数学洛谷月赛

宇宙分解

Description

You are given a sequence aa and two operations:

  1. Choose ai<ai+1a_i < a_{i+1} and delete ai+1a_{i+1}.
  2. Choose ai<ai+1a_i < a_{i+1} and swap these two numbers.

You must repeatedly perform these operations until no more operations can be done. How many distinct sequences can be obtained at the end?

Input Format

The first line contains an integer nn.

The second line contains nn integers, where the ii-th integer is aia_i.

Output Format

Output an integer representing the number of distinct sequences obtained at the end, modulo 998244353998244353.

5
4 5 2 3 1
4
4
2 2 2 2
1

Hint

Sample Explanation

For Sample #1, there are four possible outcomes:

  • [4,2,1][4, 2, 1]: Obtained by performing two deletions to remove 55 and 33.
  • [5,4,2,1][5, 4, 2, 1]: Obtained by deleting 33 and moving 55 to the front.
  • [5,4,3,2,1][5, 4, 3, 2, 1]: Obtained by performing two swaps to sort the sequence.
  • [4,3,2,1][4, 3, 2, 1]: Obtained by deleting 55 and then sorting the sequence.

For Sample #2, no operations can be performed initially.

Constraints

Test nn\le aia_i\le Special Properties
11 55 None
232\sim 3 10310^3 All aia_i are distinct
454\sim 5 10510^5 10910^9
676\sim 7 55 None
8108\sim 10 10910^9

For all test cases, 1n1051 \le n \le 10^5, 1ai1091 \le a_i \le 10^9.

Generated by Deepseek V3.