CF1909F1.Small Permutation Problem (Easy Version)
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
⠀
In the easy version, the ai are in the range [0,n]; in the hard version, the ai are in the range [−1,n] and the definition of good permutation is slightly different. You can make hacks only if all versions of the problem are solved.
You are given an integer n and an array a1,a2…,an of integers in the range [0,n].
A permutation p1,p2,…,pn of [1,2,…,n] is good if, for each i, the following condition is true:
- the number of values ≤i in [p1,p2,…,pi] is exactly ai.
Count the good permutations of [1,2,…,n], modulo 998244353.
⠀
在简单版本中,ai 的取值范围为 [0,n];在困难版本中,ai 的取值范围为 [−1,n],且“好排列”的定义略有不同。仅当本题的所有版本均已被解决时,才允许进行 hack。
给定一个整数 n 和一个长度为 n 的整数数组 a1,a2,…,an,其中每个 ai 均属于区间 [0,n]。
排列 p1,p2,…,pn 是 [1,2,…,n] 的一个好排列,当且仅当对每个 i,以下条件成立:
- 在子数组 [p1,p2,…,pi] 中,值 ≤i 的元素个数恰好为 ai。
请计算 [1,2,…,n] 的好排列的个数,并对 998244353 取模。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains a single integer n (1≤n≤2⋅105) — the length of the array a.
The second line of each test case contains n integers a1,a2,…,an (0≤ai≤n), which describe the conditions for a good permutation.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)—— 表示数组 a 的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(0≤ai≤n),用于描述“好排列”的条件。
保证所有测试用例的 n 值之和不超过 2⋅105。
输出格式
For each test case, output a single line containing the number of good permutations, modulo 998244353.
对于每个测试用例,输出一行,包含好排列的数量对 998244353 取模的结果。
输入输出样例
输入#1
5 5 1 2 3 4 5 6 0 2 2 2 4 6 6 0 1 3 4 5 5 6 1 2 3 2 4 6 15 0 0 1 1 1 2 3 4 5 6 7 9 11 13 15
输出#1
1 4 0 0 532305727
说明/提示
In the first test case, the only good permutation is [1,2,3,4,5].
In the second test case, there are 4 good permutations: [2,1,5,6,3,4], [2,1,5,6,4,3], [2,1,6,5,3,4], [2,1,6,5,4,3]. For example, [2,1,5,6,3,4] is good because:
- a1=0, and there are 0 values ≤1 in [p1]=[2];
- a2=2, and there are 2 values ≤2 in [p1,p2]=[2,1];
- a3=2, and there are 2 values ≤3 in [p1,p2,p3]=[2,1,5];
- a4=2, and there are 2 values ≤4 in [p1,p2,p3,p4]=[2,1,5,6];
- a5=4, and there are 4 values ≤5 in [p1,p2,p3,p4,p5]=[2,1,5,6,3];
- a6=6, and there are 6 values ≤6 in [p1,p2,p3,p4,p5,p6]=[2,1,5,6,3,4].
In the third test case, there are no good permutations, because there are no permutations with a6=5 values ≤6 in [p1,p2,p3,p4,p5,p6].
在第一个测试用例中,唯一的好排列是 [1,2,3,4,5]。
在第二个测试用例中,共有 4 个好排列:[2,1,5,6,3,4]、[2,1,5,6,4,3]、[2,1,6,5,3,4]、[2,1,6,5,4,3]。例如,[2,1,5,6,3,4] 是好排列,因为:
- a1=0,且在 [p1]=[2] 中有 0 个值 ≤1;
- a2=2,且在 [p1,p2]=[2,1] 中有 2 个值 ≤2;
- a3=2,且在 [p1,p2,p3]=[2,1,5] 中有 2 个值 ≤3;
- a4=2,且在 [p1,p2,p3,p4]=[2,1,5,6] 中有 2 个值 ≤4;
- a5=4,且在 [p1,p2,p3,p4,p5]=[2,1,5,6,3] 中有 4 个值 ≤5;
- a6=6,且在 [p1,p2,p3,p4,p5,p6]=[2,1,5,6,3,4] 中有 6 个值 ≤6。
在第三个测试用例中,不存在好排列,因为没有任何排列能满足:在 [p1,p2,p3,p4,p5,p6] 中恰好有 a6=5 个值 ≤6。
输入解题思路,AI测评打分。不知道怎么写?