#P13947. [EC Final 2019] Permutation

    ID: 15740 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2019线段树分治ICPC笛卡尔树EC Final

[EC Final 2019] Permutation

题目描述

You are given a permutation p1,p2,,pnp_1, p_2, \dots, p_n. You can do the following operations repeatedly:

  • Choose an interval $p_{l}, p_{l+1}, \dots, p_{l+c} (l \geq 1, l+c \leq n)$ where plp_l is the smallest element in this interval, you can permutate pl+1,,pl+cp_{l+1}, \dots, p_{l+c} in arbitrary way.
  • Choose an interval $p_{l}, p_{l+1}, \dots, p_{l+c} (l\geq 1, l+c \leq n)$ where pl+cp_{l+c} is the smallest element in this interval, you can permutate pl,,pl+c1p_{l}, \dots, p_{l+c-1} in arbitrary way.

You want to know how many distinct permutations you can get using operations. The answer can be large, output the answer modulo 998244353998244353.

输入格式

The first line contains an integer TT denoting the number of test cases (1T1000001\le T\le 100000).

The first line in a test case contains two integers nn and cc (2c5000002\le c \le 500000, 2n5000002\le n\le 500000). The sum of nn over all test cases does not exceed 500000500000.

The second line in a test case contains a permutation p1,,pnp_1,\ldots, p_n (1pin1\le p_i\le n).

输出格式

For each test case, output one line containing the answer modulo 998244353998244353.

5
5 3
3 4 2 1 5
5 4
4 2 1 3 5
5 2
4 5 3 1 2
5 3
4 3 2 1 5
5 2
2 3 1 5 4
6
1
4
6
4