CF1909F1.Small Permutation Problem (Easy Version)

普及/提高-

通过率:0%

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 998244353998\,244\,353 .

输入格式

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

The first line of each test case contains a single integer nn ( 1n21051 \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 ( 0ain0 \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 21052 \cdot 10^5 .

输出格式

For each test case, output a single line containing the number of good permutations, modulo 998244353998\,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] .

首页