#abc221e. E - LEQ

E - LEQ

Score : 500500 points

问题描述

已知一个包含 NN 个整数的序列:A=(A1,A2,,AN)A = (A_1, A_2, \dots, A_N)

找出满足以下条件的(不一定连续的)子序列 A=(A1,A2,,Ak)A'=(A'_1,A'_2,\ldots,A'_k) 的数量,其中子序列长度至少为 22

  • A1AkA'_1 \leq A'_k

由于计数可能非常庞大,计算结果请模 998244353998244353 后输出。

这里需要注意的是,即使两个子序列在顺序上相同,但如果它们源自不同的索引集合,则被视为不同的子序列。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Given is a sequence of NN integers: A=(A1,A2,,AN)A = (A_1, A_2, \dots, A_N).

Find the number of (not necessarily contiguous) subsequences A=(A1,A2,,Ak)A'=(A'_1,A'_2,\ldots,A'_k) of length at least 22 that satisfy the following condition:

  • A1AkA'_1 \leq A'_k.

Since the count can be enormous, print it modulo 998244353998244353.

Here, two subsequences are distinguished when they originate from different sets of indices, even if they are the same as sequences.

Constraints

  • 2N3×1052 \leq N \leq 3 \times 10^5
  • 1Ai1091 \leq A_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \ldots ANA_N

Output

Print the number of (not necessarily contiguous) subsequences A=(A1,A2,,Ak)A'=(A'_1,A'_2,\ldots,A'_k) of length at least 22 that satisfy the condition in Problem Statement.

Sample Input 1

3
1 2 1

Sample Output 1

3

A=(1,2,1)A=(1,2,1) has four (not necessarily contiguous) subsequences of length at least 22: (1,2)(1,2), (1,1)(1,1), (2,1)(2,1), (1,2,1)(1,2,1).

Three of them, (1,2)(1,2), (1,1)(1,1), (1,2,1)(1,2,1), satisfy the condition in Problem Statement.

Sample Input 2

3
1 2 2

Sample Output 2

4

Note that two subsequences are distinguished when they originate from different sets of indices, even if they are the same as sequences.

In this Sample, there are four subsequences, (1,2)(1,2), (1,2)(1,2), (2,2)(2,2), (1,2,2)(1,2,2), that satisfy the condition.

Sample Input 3

3
3 2 1

Sample Output 3

0

There may be no subsequence that satisfies the condition.

Sample Input 4

10
198495780 28463047 859606611 212983738 946249513 789612890 782044670 700201033 367981604 302538501

Sample Output 4

830

update @ 2024/3/10 09:45:19