#P10103. [GDKOI2023 提高组] 错排

[GDKOI2023 提高组] 错排

Problem Description

X has recently been studying the derangement problem, so he started thinking about a variant: how many permutations pp of length nn satisfy that for positions imi \le m, pi>mp_i > m, and for all positions ii, piip_i \ne i?

X came up with a total of TT such queries. Can you tell him the answer for each query?

Since the answer may be too large, you only need to output it modulo 998244353998244353.

Input Format

The first line contains an integer TT, representing the number of queries.

The next TT lines each contain two integers n,mn, m.

Output Format

Output TT lines, each containing one integer: the answer modulo 998244353998244353.

6
8 0
8 4
100 10
1000 100
10000 1000
100000 10000

14833
576
548326276
694205000
493811811
135068319

Hint

For 100% of the testdata, 0T2×1050 \le T \le 2 \times 10^5, 0mn2×1050 \le m \le n \le 2 \times 10^5.

This problem uses bundled subtasks.

  • Subtask 1 (1pts): T=0T = 0.
  • Subtask 2 (9pts): T10T \le 10, n,m8n, m \le 8.
  • Subtask 3 (10pts): m=0m = 0.
  • Subtask 4 (20pts): n,m5000n, m \le 5000.
  • Subtask 5 (20pts): T10T \le 10.
  • Subtask 6 (40pts): No special constraints.

Translated by ChatGPT 5