AtCoder Japan Open -予選-(AtCoder Regular Contest 186)
B
Typical Permutation Descriptor
AtCoder
⌀ 1677
原题
← AC →
翻译中…

Problem Statement

翻译中…

You are given a sequence of integers $(A_1,\dots,A_N)$ of length $N$. This sequence satisfies $0\le A_i < i$ for each $i=1,\dots,N$. Find the number of permutations $(P_1,\dots,P_N)$ of $(1,\dots,N)$ that satisfy the following conditions, modulo $998244353$.

翻译中…
  • For each $i=1,\dots,N$:
  • $P_j > P_i$ for any integer $j$ with $A_i < j < i$
    • $P_{A_i} < P_i$ if $A_i > 0$
翻译中…

For the sequence $(A_1,\dots,A_N)$ given in the input, it is guaranteed that there exists a permutation satisfying the conditions.

翻译中…

Constraints

翻译中…
  • $1\le N\le 3\times 10^5$
  • $0\le A_i \lt i$
  • For $A_1,\dots,A_N$, there exists a permutation satisfying the conditions in the problem statement.
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
A_1 A_2 \dots A_N

翻译中…

Output

翻译中…

Print the number of permutations satisfying the conditions, modulo $998244353$.

翻译中…

样例

Input #1
4
0 1 0 3
Output #1
3
There are three such permutations: $(2, 3, 1, 4)$, $(2, 4, 1, 3)$, and $(3, 4, 1, 2)$.
Input #2
22
0 1 2 2 2 2 2 2 1 9 9 9 9 0 14 15 15 15 14 19 19 19
Output #2
353820794
The answer is $353820794$, which is $2350309500$ modulo $998244353$.
题目信息
题号
arc186_b
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。