CF1909F1.Small Permutation Problem (Easy Version)

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Andy Tunstall - MiniBoss

⠀

In the easy version, the aia_i are in the range [0,n][0, n]; in the hard version, the aia_i are in the range [−1,n][-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 nn and an array a1,a2…,ana_1, a_2 \dots, a_n of integers in the range [0,n][0, n].

A permutation p1,p2,…,pnp_1, p_2, \dots, p_n of [1,2,…,n][1, 2, \dots, n] is good if, for each ii, the following condition is true:

  • the number of values ≤i\leq i in [p1,p2,…,pi][p_1, p_2, \dots, p_i] is exactly aia_i.

Count the good permutations of [1,2,…,n][1, 2, \dots, n], modulo 998 244 353998\,244\,353.

Andy Tunstall - MiniBoss

⠀

在简单版本中,aia_i 的取值范围为 [0,n][0, n];在困难版本中,aia_i 的取值范围为 [−1,n][-1, n],且“好排列”的定义略有不同。仅当本题的所有版本均已被解决时,才允许进行 hack。

给定一个整数 nn 和一个长度为 nn 的整数数组 a1,a2,…,ana_1, a_2, \dots, a_n,其中每个 aia_i 均属于区间 [0,n][0, n]。

排列 p1,p2,…,pnp_1, p_2, \dots, p_n 是 [1,2,…,n][1, 2, \dots, n] 的一个好排列,当且仅当对每个 ii,以下条件成立:

  • 在子数组 [p1,p2,…,pi][p_1, p_2, \dots, p_i] 中,值 ≤i\leq i 的元素个数恰好为 aia_i。

请计算 [1,2,…,n][1, 2, \dots, n] 的好排列的个数,并对 998 244 353998\,244\,353 取模。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5) — the length of the array aa.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤n0 \le a_i \le n), which describe the conditions for a good permutation.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5)—— 表示数组 aa 的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤n0 \le a_i \le n),用于描述“好排列”的条件。

保证所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output a single line containing the number of good permutations, modulo 998 244 353998\,244\,353.

对于每个测试用例,输出一行,包含好排列的数量对 998 244 353998\,244\,353 取模的结果。

输入输出样例

  • 输入#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][1, 2, 3, 4, 5].

In the second test case, there are 44 good permutations: [2,1,5,6,3,4][2, 1, 5, 6, 3, 4], [2,1,5,6,4,3][2, 1, 5, 6, 4, 3], [2,1,6,5,3,4][2, 1, 6, 5, 3, 4], [2,1,6,5,4,3][2, 1, 6, 5, 4, 3]. For example, [2,1,5,6,3,4][2, 1, 5, 6, 3, 4] is good because:

  • a1=0a_1 = 0, and there are 00 values ≤1\leq 1 in [p1]=[2][p_1] = [2];
  • a2=2a_2 = 2, and there are 22 values ≤2\leq 2 in [p1,p2]=[2,1][p_1, p_2] = [2, 1];
  • a3=2a_3 = 2, and there are 22 values ≤3\leq 3 in [p1,p2,p3]=[2,1,5][p_1, p_2, p_3] = [2, 1, 5];
  • a4=2a_4 = 2, and there are 22 values ≤4\leq 4 in [p1,p2,p3,p4]=[2,1,5,6][p_1, p_2, p_3, p_4] = [2, 1, 5, 6];
  • a5=4a_5 = 4, and there are 44 values ≤5\leq 5 in [p1,p2,p3,p4,p5]=[2,1,5,6,3][p_1, p_2, p_3, p_4, p_5] = [2, 1, 5, 6, 3];
  • a6=6a_6 = 6, and there are 66 values ≤6\leq 6 in [p1,p2,p3,p4,p5,p6]=[2,1,5,6,3,4][p_1, p_2, p_3, p_4, p_5, p_6] = [2, 1, 5, 6, 3, 4].

In the third test case, there are no good permutations, because there are no permutations with a6=5a_6 = 5 values ≤6\leq 6 in [p1,p2,p3,p4,p5,p6][p_1, p_2, p_3, p_4, p_5, p_6].

在第一个测试用例中,唯一的好排列是 [1,2,3,4,5][1, 2, 3, 4, 5]。

在第二个测试用例中,共有 44 个好排列:[2,1,5,6,3,4][2, 1, 5, 6, 3, 4]、[2,1,5,6,4,3][2, 1, 5, 6, 4, 3]、[2,1,6,5,3,4][2, 1, 6, 5, 3, 4]、[2,1,6,5,4,3][2, 1, 6, 5, 4, 3]。例如,[2,1,5,6,3,4][2, 1, 5, 6, 3, 4] 是好排列,因为:

  • a1=0a_1 = 0,且在 [p1]=[2][p_1] = [2] 中有 00 个值 ≤1\leq 1;
  • a2=2a_2 = 2,且在 [p1,p2]=[2,1][p_1, p_2] = [2, 1] 中有 22 个值 ≤2\leq 2;
  • a3=2a_3 = 2,且在 [p1,p2,p3]=[2,1,5][p_1, p_2, p_3] = [2, 1, 5] 中有 22 个值 ≤3\leq 3;
  • a4=2a_4 = 2,且在 [p1,p2,p3,p4]=[2,1,5,6][p_1, p_2, p_3, p_4] = [2, 1, 5, 6] 中有 22 个值 ≤4\leq 4;
  • a5=4a_5 = 4,且在 [p1,p2,p3,p4,p5]=[2,1,5,6,3][p_1, p_2, p_3, p_4, p_5] = [2, 1, 5, 6, 3] 中有 44 个值 ≤5\leq 5;
  • a6=6a_6 = 6,且在 [p1,p2,p3,p4,p5,p6]=[2,1,5,6,3,4][p_1, p_2, p_3, p_4, p_5, p_6] = [2, 1, 5, 6, 3, 4] 中有 66 个值 ≤6\leq 6。

在第三个测试用例中,不存在好排列,因为没有任何排列能满足:在 [p1,p2,p3,p4,p5,p6][p_1, p_2, p_3, p_4, p_5, p_6] 中恰好有 a6=5a_6 = 5 个值 ≤6\leq 6。

输入解题思路,AI测评打分。不知道怎么写?

首页