QOJ.ac

QOJ

時間限制: 3 s 記憶體限制: 2048 MB 總分: 100 难度: [顯示] 可 Hack ✓

#18200. 备用账号 2

统计

众所周知,zh0ukangyang = orzdevinwang。

在 6202 年,当没有人想再打 Universal Cup 时,小青鱼(Little Cyan Fish)决定举办国际钓鱼奥林匹克竞赛(International Olympiad in Fishing)。有 $n$ 个人有兴趣参加这项活动,但是……好吧,他们没有遵守单账号规则:每个参赛者都注册了两个不同的账号!

这很糟糕,但幸运的是,他们都是非常好的人,绝不会利用多账号作弊。每个参赛者都遵循以下策略:在任何时刻,他们总是会使用自己两个账号中排名较差(即排名数字较大)的那一个来参赛。也就是说,如果一个参赛者拥有的两个账号排名分别为 $x$ 和 $y$,他们将在下一场比赛中使用排名为 $\max(x, y)$ 的账号。

设 $p_i$ 表示当前排名为 $i$ 的账号,并根据初始排名将账号标记为 $1$ 到 $2n$(因此在开始时 $p_i = i$)。接着,在接下来的 $m$ 场比赛中,每场比赛恰好有一位参赛者参加。具体来说,在第 $i$ 场比赛中($1 \le i \le m$),当前排名为 $k_i$($k_i \ge 2$)的账号参赛,并且其排名正好上升一位(即在比赛后,$p_{k_i}$ 和 $p_{k_i-1}$ 交换)。

小青鱼想要弄清楚哪些账号属于同一个选手。他注意到参赛者的策略透露了关于账号持有者的一些信息。请帮助他计算将这 $2n$ 个账号两两配对成 $n$ 个参赛者的可能方案数,使其与比赛历史相符。由于答案可能很大,请将其对 $998\,244\,353$ 取模后输出。

输入格式

输入的第一行包含两个整数 $n$ 和 $m$($1 \le n, m \le 5\,000$),分别表示选手数量和比赛场数。

接下来的 $m$ 行,每行包含一个整数 $k_i$($2 \le k_i \le 2n$),表示在第 $i$ 场比赛中,当前排名为 $k_i$ 的账号参加了比赛。

输出格式

输出单行,包含一个整数,表示可能的账号配对方案数对 $998\,244\,353$ 取模后的结果。

样例

输入样例 1

1 1
2

输出样例 1

1

输入样例 2

2 2
2
3

输出样例 2

0

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1946EditorialOpenNew Editorial for Problem #18200ucup-team78702026-06-16 15:18:52View
#1942EditorialOpen没有人喜欢我呜呜呜GotoHiotori2026-06-16 14:07:50View
#1944EditorialOpenNew Editorial for Problem #18200KnownError_2026-06-16 14:04:53View

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.