#P4566. [CTSC2018] 青蕈领主

    ID: 3456 远端评测题 3000ms 500MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2018WC/CTSC/集训队O2优化分治强连通分量,缩点快速傅里叶变换 FFT

[CTSC2018] 青蕈领主

Description

Because of a calculus course, Xiao Lü has become very interested in the concept of "continuity". He plans to bring the concept of continuity to sequences of integers. He defines an integer sequence of length mm to be continuous if and only if the difference between the maximum and minimum elements in the sequence does not exceed m1m-1. For example, {1,3,2}\{1,3,2\} is continuous, while {1,3}\{1,3\} is not.

One day, Xiao Lü’s direct supervisor, Boss Ban, gave him TT permutations of length nn. Delighted, Xiao Lü determined, for each permutation, whether each interval is "continuous" as he defined. However, he felt that "continuous" intervals contained within other "continuous" intervals were not good enough. Therefore, for all "continuous" intervals in each permutation with the same right endpoint, he recorded only the length of the longest such "continuous" interval. In other words, for each permutation given by Boss Ban, he recorded for each 1in1 \le i \le n the length LiL_i of the longest "continuous" interval whose right endpoint is ii. Clearly, this length is at least 11, because all integer sequences of length 11 are continuous.

After finishing all this, Xiao Lü climbed onto his green bed and had a lovely green dream.

But when he woke up the next day, he was shocked to find that all the permutations Boss Ban had given him were gone, leaving only the TT recorded sets of information. Knowing he was doomed, yet being a curious young man, he still wanted to know: for each set of information, how many length-nn permutations are consistent with it?

Since Xiao Lü has already given up on treatment, you only need to tell him each answer modulo 998244353998244353.

We do not guarantee that there exists at least one permutation consistent with the information, because Xiao Lü is human and can make mistakes.

Input Format

The first line contains two integers T,nT, n, representing the number of permutations Boss Ban gave and the length of each permutation.

The next TT lines each describe one set of information and contain nn positive integers. In the ii-th set, the jj-th integer from left to right Li,jL_{i,j} denotes, in the ii-th permutation, the length of the longest "continuous" interval whose right endpoint is the jj-th position.

Within each line, if there are multiple numbers, they are separated by a single space.

Output Format

For each set of information, output a single integer on its own line representing the number of possible permutations modulo 998244353998244353. Since the computer is doing the calculation, we will not give you a chance to make a mistake.

1 3
1 1 3
2

Hint

Constraints

测试点编号 nn\le TT\le 特殊性质
1~2 10 1 None
3~4 100
5 300 1 Li,j=jL_{i,j}=j
6 Li,j=1L_{i,j}=1j<nj<n
7~8 100 None
9 1000 1 Li,j=1L_{i,j}=1j<nj<n
10~12 100 None
13~16 5000
17~20 50000

For all testdata, $1 \le T \le 100, 1 \le n \le 50000, 1 \le L_{i,j} \le j$.
Some test points have large input size; please be mindful of input speed.

Translated by ChatGPT 5