#P7292. 「EZEC-5」「KrOI2021」Chasse Neige 加强版

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

「EZEC-5」「KrOI2021」Chasse Neige 加强版

Background

"I like snow."

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

Problem Description

The difference from the original problem is that the range of rr is enlarged. This should be able to block the O(nlog2n)O(n\log^2 n) 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 O(nlogn)O(n\log n), please pay attention to constant-factor optimization.

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 \le i \le n - 1) such that πi1<πi\pi_{i-1} < \pi_i and πi>πi+1\pi_i > \pi_{i+1}.

Take the answer modulo 998244353998244353.

Input Format

The first line contains two integers T,rT, r, representing the number of queries and the range of possible values 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 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 1616 in total, so the answer is 1616.

Constraints

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

Translated by ChatGPT 5