#arc178d. D - Delete Range Mex
D - Delete Range Mex
Score : points
问题陈述
给定一个正整数 和一个包含 个非负整数的序列 。
这里, 中的所有元素都是介于 和 之间的不同整数。
找出排列 的数量,模 ,满足以下条件的 :
- 在将序列 初始化为 后,通过重复以下操作若干次,可以使 :
- 选择 和 使得 ,如果 包含在 中,则将其从 中移除。
什么是 ?对于有限的非负整数集合 , 定义为不在 中的最小非负整数。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given a positive integer and a sequence of non-negative integers .
Here, all elements of are distinct integers between and , inclusive.
Find the number, modulo , of permutations of that satisfy the following condition.
- After initializing a sequence to , it is possible to make by repeating the following operation some number of times:
- Choose and such that , and if is contained in , remove it from .
What is ? For a finite set of non-negative integers, is defined as the smallest non-negative integer that is not in .
Constraints
- All elements of are distinct.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
4 2
1 3
Sample Output 1
8
After initializing , it is possible to make using the following steps:
- Choose , remove from , making .
- Choose , remove from , making .
Thus, satisfies the condition.
There are eight permutations that satisfy the condition, including the above, so print .
Sample Input 2
4 4
0 3 2 1
Sample Output 2
1
Only satisfies the condition.
Sample Input 3
16 7
9 2 4 0 1 6 7
Sample Output 3
3520
Sample Input 4
92 4
1 67 16 7
Sample Output 4
726870122
Find the count modulo .