102214: [AtCoder]ABC221 E - LEQ
Description
Score : $500$ points
Problem Statement
Given is a sequence of $N$ integers: $A = (A_1, A_2, \dots, A_N)$.
Find the number of (not necessarily contiguous) subsequences $A'=(A'_1,A'_2,\ldots,A'_k)$ of length at least $2$ that satisfy the following condition:
- $A'_1 \leq A'_k$.
Since the count can be enormous, print it modulo $998244353$.
Here, two subsequences are distinguished when they originate from different sets of indices, even if they are the same as sequences.
Constraints
- $2 \leq N \leq 3 \times 10^5$
- $1 \leq A_i \leq 10^9$
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
$N$ $A_1$ $A_2$ $\ldots$ $A_N$
Output
Print the number of (not necessarily contiguous) subsequences $A'=(A'_1,A'_2,\ldots,A'_k)$ of length at least $2$ that satisfy the condition in Problem Statement.
Sample Input 1
3 1 2 1
Sample Output 1
3
$A=(1,2,1)$ has four (not necessarily contiguous) subsequences of length at least $2$: $(1,2)$, $(1,1)$, $(2,1)$, $(1,2,1)$.
Three of them, $(1,2)$, $(1,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)$, $(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
Input
题意翻译
给定一个长度为 $N$ 的序列 $A=(A_1,A_2,..., A_N)$。 求出子序列的总数,使得对于任意的子序列 $A'=(A'_1,A'_2,...,A'_k)$ ,满足 $A'_1 \le A'_k$ 。 **答案对 $998244353$ 取模。**Output
得分:500分
问题描述
给定一个包含 $N$ 个整数的序列:$A = (A_1, A_2, \dots, A_N)$。
找出满足以下条件的长度至少为 $2$ 的(不一定是连续的)子序列 $A'=(A'_1,A'_2,\ldots,A'_k)$ 的数量:
- $A'_1 \leq A'_k$。
由于计数可能非常大,请对 $998244353$ 取模后输出。
这里,如果两个子序列源自不同的索引集,即使它们作为序列相同,也认为它们是不同的。
约束条件
- $2 \leq N \leq 3 \times 10^5$
- $1 \leq A_i \leq 10^9$
- 输入中的所有值都是整数。
输入
输入通过标准输入以以下格式给出:
$N$ $A_1$ $A_2$ $\ldots$ $A_N$
输出
输出满足问题描述中条件的(不一定是连续的)子序列 $A'=(A'_1,A'_2,\ldots,A'_k)$ 的数量。
样例输入 1
3 1 2 1
样例输出 1
3
$A=(1,2,1)$ 有四个长度至少为 $2$ 的(不一定是连续的)子序列:$(1,2)$, $(1,1)$, $(2,1)$, $(1,2,1)$。
其中三个,$(1,2)$, $(1,1)$, $(1,2,1)$,满足问题描述中的条件。
样例输入 2
3 1 2 2
样例输出 2
4
注意,即使两个子序列作为序列相同,只要它们源自不同的索引集,就认为它们是不同的。
在这个样例中,有四个满足条件的子序列,$(1,2)$, $(1,2)$, $(2,2)$, $(1,2,2)$。
样例输入 3
3 3 2 1
样例输出 3
0
可能没有满足条件的子序列。
样例输入 4
10 198495780 28463047 859606611 212983738 946249513 789612890 782044670 700201033 367981604 302538501
样例输出 4
830