#P7292. 「EZEC-5」「KrOI2021」Chasse Neige 加强版
「EZEC-5」「KrOI2021」Chasse Neige 加强版
Description
The difference from the original problem is that the range of is enlarged. This should be able to block the divide-and-conquer FFT solution. If there is a divide-and-conquer FFT solution that can pass, please contact me. Also, if your solution is , please pay attention to constant-factor optimization.
Rikka gives you queries. In each query, two positive integers are given. You need to tell Rikka how many permutations of length satisfy the following conditions:
-
.
-
.
-
There exist exactly positions such that and .
Take the answer modulo .
Input Format
The first line contains two integers , representing the number of queries and the range of possible values of .
The next lines each contain two integers , with the meaning as described above.
Output Format
Output lines. Each line contains one positive integer, the answer modulo .
2 10
3 1
5 2
2
16
Hint
Sample Explanation 1
For the first query, . Both and satisfy the conditions, so the answer is .
For the second query, the valid permutations are:
$$(1,3,2,5,4),(1,4,2,5,3),(1,4,3,5,2),(1,5,2,4,3),(1,5,3,4,2)\\(2,3,1,5,4),(2,4,1,5,3),(2,4,3,5,1),(2,5,1,4,3),(2,5,3,4,1)\\(3,4,1,5,2),(3,4,2,5,1),(3,5,1,4,2),(3,5,2,4,1),(4,5,1,3,2),(4,5,2,3,1)$$There are in total, so the answer is .
Constraints
For of the testdata, , , and $\max(1, \lfloor\frac{n-1}{2}\rfloor - 10) \le k \le \lfloor\frac{n-1}{2}\rfloor$.
Translated by ChatGPT 5
京公网安备 11011102002149号