logo AlgoBeat OnlineJudge
登录 注册

#217363. [ICPC 2026 Xi'an I] Transform

内存限制:512 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Yuki has a multiset of size and an integer .

Yuki defines a transformation as follows:

  • Choose a subset of (where can be an empty set), remove from , and add the of to .

Now, Yuki wants to perform several transformations such that becomes . You need to help Yuki find the minimum number of transformations required to make equal to . Since the answer can be very large, you only need to output the answer modulo .

It can be proven that there always exists at least one sequence of operations that can transform into .

: The of a multiset is the smallest non-negative integer that does not appear in the multiset. For example, , , and .

输入格式

This problem contains multiple test cases.

The first line contains a positive integer , representing the number of test cases.

For each test case:

  • The first line contains two integers .
  • The second line contains integers .

It is guaranteed that the sum of over all test cases does not exceed .

输出格式

For each test case, output a single line containing an integer representing the minimum number of transformations required to make equal to , modulo .

样例

样例输入 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

数据范围与提示

For the 1st test case:

  • Yuki can choose in the 1st transformation, making , and then choose in the 2nd transformation, making .
  • It can be proven that no sequence of operations with fewer transformations exists, so the answer is .

For the 2nd test case:

  • Yuki does not need to perform any transformations to make , so the answer is .

For the 3rd test case:

  • Yuki can choose in the 1st transformation, making , choose in the 2nd transformation, making , and then choose in the 3rd transformation, making .
  • It can be proven that no sequence of operations with fewer transformations exists, so the answer is .

For the 4th test case:

  • Yuki can choose in the 1st transformation, making , and then choose in the 2nd transformation, making .
  • It can be proven that no sequence of operations with fewer transformations exists, so the answer is .

For the 5th test case:

  • Yuki can directly choose in the 1st transformation, making .
  • It can be proven that no sequence of operations with fewer transformations exists, so the answer is .