No.2815 Smaller than all
タグ : / 解いたユーザー数 21
作問者 :
Magentor
/ テスター :
highlighter
keisuke6
fact493
Problem Statement
You are given a sequence of positive integers $A=(A_1,A_2,\dots,A_N)$ of length $N$. Consider the following problem.
You are givenan integer sequencea sequence of positive integers (corrected at 21:53) $S$. Find the lexicographically largest sequence of positive integers $T$ of length $N$ that satisfies the following condition. It can be shown that the lexicographically largest $T$ always exists. (added at 22:00)
- Every (not necessarily contiguous) subsequence of length $|S|$ of the sequence of positive integers $T$ is lexicographically less than or equal to $S$.
Find the number, modulo $998244353$, of sequences of positive integers $S$ of length at least $1$ and at most $N$ such that the answer to the problem above is equal to $A=(A_1,A_2,\dots,A_N)$.
Here, a subsequence of an integer sequence is an integer sequence obtained by deleting $0$ or more elements from it and arranging the remaining elements without changing their order.
What is the lexicographical order on sequences?
$A=(A_1,A_2,\dots,A_{|A|})$ is lexicographically less than or equal to $B=(B_1,B_2,\dots,B_{|B|})$ if one of the following $2$ conditions holds. Here, $|A|,|B|$ denote the lengths of $A,B$, respectively.
- $|A| \leq |B|$ and $(A_1,A_2,\dots,A_{|A|})=(B_1,B_2,\dots,B_{|A|})$.
- There exists an integer $1 \leq i \leq \min(|A|,|B|)$ such that both of the following $2$ statements hold.
- $(A_1,A_2,\dots,A_{i-1})=(B_1,B_2,\dots,B_{i-1})$
- $A_i<B_i$
Constraints
- All input values are integers.
- $1 \leq N \leq 2 \times 10^5$
- $1 \leq A_i \leq10^9$
Input
The input is given from Standard Input in the following format.
$N$ $A_1\ A_2\ \dots\ A_N$
Output
Print the answer in $1$ line.
Sample
Sample 1
Input
3 1 1 2
Output
2
It can be proved that only $S=(1,1,2),(1,2)$ satisfy the condition. For example, when $S=(1,2)$, the possible subsequences of $(1,1,2)$ are $(1,1),(1,2),(1,2)$, all of which are lexicographically less than or equal to $(1,2)$. It can also be verified that $(1,1,2)$ is the lexicographically largest in this case, so $(1,2)$ satisfies the condition.
Sample 2
Input
5 1 1 1 1 1
Output
5
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。