QOJ.ac

QOJ

시간 제한: 1 s 메모리 제한: 512 MB 총점: 100 해킹 가능 ✓

#17348. 变换

통계

Yuki 有一个大小为 $n$ 的多重集 $S = \{s_1, \dots, s_n\}$ 和一个整数 $k$。

Yuki 定义了一次变换如下:

  • 选择 $S$ 的一个子集 $S'$(其中 $S'$ 可以是空集),从 $S$ 中移除 $S'$,并将 $S'$ 的 $\text{mex}^*$ 加入到 $S$ 中。

现在,Yuki 想要进行若干次变换,使得 $S$ 变为 $\{k\}$。你需要帮助 Yuki 求出使 $S$ 等于 $\{k\}$ 所需的最少变换次数。由于答案可能非常大,你只需要输出答案对 $998244353$ 取模后的结果。

可以证明,总是存在至少一种操作序列可以将 $S$ 变换为 $\{k\}$。

$^*$: 一个多重集的 $\text{mex}$ 是指未在其中出现的最小非负整数。例如,$\text{mex}\{0, 1, 2\} = 3$,$\text{mex}\{1, 0, 3, 1\} = 2$,且 $\text{mex} \emptyset = 0$。

输入格式

本题包含多个测试用例。

第一行包含一个正整数 $t$ ($1 \le t \le 10^5$),表示测试用例的数量。

对于每个测试用例:

  • 第一行包含两个整数 $n, k$ ($1 \le n \le 5 \cdot 10^5$, $0 \le k \le 10^9$)。
  • 第二行包含 $n$ 个整数 $s_1, \dots, s_n$ ($0 \le s_i \le 10^9$)。

保证所有测试用例中 $n$ 的总和不超过 $5 \cdot 10^5$。

输出格式

对于每个测试用例,输出一行,包含一个整数,表示将 $S$ 变为 $\{k\}$ 所需的最少变换次数对 $998244353$ 取模后的结果。

样例

输入样例 1

6
1 2
1
1 4
4
3 3
0 2 2
4 2
1 0 3 2
4 3
2 1 0 2
3 52
20 2 6

输出样例 1

2
0
3
2
1
262875292

说明

对于第 1 个测试用例:

  • Yuki 可以在第 1 次变换中选择 $S' = \emptyset$,使得 $S = \{0, 1\}$,然后在第 2 次变换中选择 $S' = \{0, 1\}$,使得 $S = \{2\}$。
  • 可以证明不存在变换次数更少的操作序列,因此答案为 2。

对于第 2 个测试用例:

  • Yuki 不需要进行任何变换即可使 $S = \{4\}$,因此答案为 0。

对于第 3 个测试用例:

  • Yuki 可以在第 1 次变换中选择 $S' = \emptyset$,使得 $S = \{0, 0, 2, 2\}$;在第 2 次变换中选择 $S' = \{0, 2\}$,使得 $S = \{0, 1, 2\}$;然后在第 3 次变换中选择 $S' = \{0, 1, 2\}$,使得 $S = \{3\}$。
  • 可以证明不存在变换次数更少的操作序列,因此答案为 3。

对于第 4 个测试用例:

  • Yuki 可以在第 1 次变换中选择 $S' = \{2, 3\}$,使得 $S = \{0, 0, 1\}$,然后在第 2 次变换中选择 $S' = \{0, 0, 1\}$,使得 $S = \{2\}$。
  • 可以证明不存在变换次数更少的操作序列,因此答案为 2。

对于第 5 个测试用例:

  • Yuki 可以在第 1 次变换中直接选择 $S' = \{0, 1, 2, 2\}$,使得 $S = \{3\}$。
  • 可以证明不存在变换次数更少的操作序列,因此答案为 1。

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.