#P7289. 「EZEC-5」「KrOI2021」Chasse Neige

    ID: 7785 远端评测题 400ms 256MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>动态规划 DP数学递推O2优化组合数学排列组合生成函数微积分积分级数快速傅里叶变换 FFT快速数论变换 NTT洛谷月赛

「EZEC-5」「KrOI2021」Chasse Neige

Background

"I like snow."

"Although I used to hate the cold, now it is my favorite."

Problem Description

Rikka gives you TT queries. In each query, two positive integers n,kn, k are given. You need to tell Rikka how many permutations π\pi of length nn satisfy the following conditions:

  • π1<π2\pi_1 < \pi_2.

  • πn1>πn\pi_{n-1} > \pi_n.

  • There exist exactly kk positions i (2in1)i \ (2 \leq i \leq n - 1) such that πi1<πi\pi_{i-1} < \pi_i and πi>πi+1\pi_i > \pi_{i+1}.

Output the answer modulo 998244353998244353.

Input Format

The first line contains two integers T,rT, r, representing the number of queries and the upper bound of the range of nn.

The next TT lines each contain two integers n,kn, k, with the meaning as described above.

Output Format

Output TT lines. Each line contains one positive integer, the answer modulo 998244353998244353.

2 10
3 1
5 2
2
16

Hint

Sample Explanation 1

For the first query, n=3,k=1n = 3, k = 1. Both (1,3,2)(1,3,2) and (2,3,1)(2,3,1) satisfy the conditions, so the answer is 22.

For the second query, the permutations that satisfy the conditions 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 1616 in total, so the answer is 1616.

Constraints

Subtask ID Points TT \leq rr \leq Other Constraints
Subtask 1 11 1010
Subtask 2 55 2×1052\times 10^5
Subtask 3 1313 11 2×1052\times 10^5
Subtask 4 2×1052\times 10^5
Subtask 5 1616 k=n12k=\lfloor\frac{n-1}{2}\rfloor and nn is odd
Subtask 6 k=n121k=\lfloor\frac{n-1}{2}\rfloor-1
Subtask 7 3636

For 100%100\% of the testdata, 1T2×1051 \leq T \leq 2\times 10^5, 3nr2×1053 \leq n \leq r \leq 2\times 10^5, and $\max(1,\lfloor\frac{n-1}{2}\rfloor-10) \leq k \leq \lfloor\frac{n-1}{2}\rfloor$.

Translated by ChatGPT 5