問題一覧 > 通常問題

No.1709 Indistinguishable by MEX

レベル : / AI推定難易度 : 1625 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 137
作問者 : chineristAC / テスター : 👑 hitonanode unti
お気に入りにしたユーザー ProblemId : 6545 / 自分の提出
問題文最終更新日: 2021-10-09 02:48:28
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 318 (順位表) の他の問題:

Problem Statement

Let $\mathrm{mex}(x_1,\ x_2,\ \dots,\ x_k)$ denote the smallest non-negative integer not contained in $x_1,\ x_2,\ \dots,\ x_k$.

You are given a permutation $P=(P_1,\ P_2,\ \dots,\ P_N)$ of length $N$ consisting of the integers from $0$ to $N-1$.

Find the number, modulo $998244353$, of permutations $Q$ consisting of the integers from $0$ to $N-1$ that satisfy the following condition.

Condition

  • For every pair of integers $1 \le l \le r \le N$, $\mathrm{mex}(P_l,\ P_{l+1},\ \dots,\ P_r)=\mathrm{mex}(Q_l,\ Q_{l+1},\ \dots,\ Q_r)$ holds.

Input

$N$
$P_1$ $P_2$ $\dots$ $P_N$
  • $1 \le N \le 2 \times 10^5$
  • $0 \le P_i \le N-1$
  • If $i\neq j$, then $P_i \neq P_j$
  • All input values are integers

Output

Print the answer.

End the output with a newline.

Sample

Sample 1
Input
4
1 3 2 0
Output
2

If $Q=(1,\ 2,\ 3,\ 0)$, then for example $\mathrm{mex}(P_2,\ P_3,\ P_4)=\mathrm{mex}(Q_2,\ Q_3,\ Q_4)=1$.

For the other $l,\ r$ as well, $\mathrm{mex}(P_l,\ P_{l+1},\ \dots,\ P_r)=\mathrm{mex}(Q_l,\ Q_{l+1},\ \dots,\ Q_r)$ holds, so $Q$ satisfies the condition.

The permutations satisfying the condition are this $Q$ and $P$ itself, for a total of $2$.

Sample 2
Input
6
3 4 0 2 1 5
Output
1

Sample 3
Input
20
6 10 8 4 14 3 19 0 13 16 2 12 17 9 15 18 11 5 1 7
Output
781469644

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。