CF1677D.Tokitsukaze and Permutations
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Tokitsukaze has a permutation p . She performed the following operation to p exactly k times: in one operation, for each i from 1 to n−1 in order, if pi > pi+1 , swap pi , pi+1 . After exactly k times of operations, Tokitsukaze got a new sequence a , obviously the sequence a is also a permutation.
After that, Tokitsukaze wrote down the value sequence v of a on paper. Denote the value sequence v of the permutation a of length n as vi=∑j=1i−1[ai<aj] , where the value of [ai<aj] define as if ai<aj , the value is 1 , otherwise is 0 (in other words, vi is equal to the number of elements greater than ai that are to the left of position i ). Then Tokitsukaze went out to work.
There are three naughty cats in Tokitsukaze's house. When she came home, she found the paper with the value sequence v to be bitten out by the cats, leaving several holes, so that the value of some positions could not be seen clearly. She forgot what the original permutation p was. She wants to know how many different permutations p there are, so that the value sequence v of the new permutation a after exactly k operations is the same as the v written on the paper (not taking into account the unclear positions).
Since the answer may be too large, print it modulo 998244353 .
输入格式
The first line contains a single integer t ( 1≤t≤1000 ) — the number of test cases. Each test case consists of two lines.
The first line contains two integers n and k ( 1≤n≤106 ; 0≤k≤n−1 ) — the length of the permutation and the exactly number of operations.
The second line contains n integers v1,v2,…,vn ( −1≤vi≤i−1 ) — the value sequence v . vi=−1 means the i -th position of v can't be seen clearly.
It is guaranteed that the sum of n over all test cases does not exceed 106 .
输出格式
For each test case, print a single integer — the number of different permutations modulo 998244353 .
输入输出样例
输入#1
3 5 0 0 1 2 3 4 5 2 -1 1 2 0 0 5 2 0 1 1 0 0
输出#1
1 6 6
说明/提示
In the first test case, only permutation p=[5,4,3,2,1] satisfies the constraint condition.
In the second test case, there are 6 permutations satisfying the constraint condition, which are:
- [3,4,5,2,1] → [3,4,2,1,5] → [3,2,1,4,5]
- [3,5,4,2,1] → [3,4,2,1,5] → [3,2,1,4,5]
- [4,3,5,2,1] → [3,4,2,1,5] → [3,2,1,4,5]
- [4,5,3,2,1] → [4,3,2,1,5] → [3,2,1,4,5]
- [5,3,4,2,1] → [3,4,2,1,5] → [3,2,1,4,5]
- [5,4,3,2,1] → [4,3,2,1,5] → [3,2,1,4,5]
So after exactly 2 times of swap they will all become a=[3,2,1,4,5] , whose value sequence is v=[0,1,2,0,0] .