#P15738. [JAG 2024 Summer Camp #2] Just Believe in Binary Search

[JAG 2024 Summer Camp #2] Just Believe in Binary Search

题目描述

Alice, who was exploring ruins in search of treasure, arrived at a corridor where the entrances to NN rooms were lined up in a row. Upon investigation, she found that the rooms were numbered uniquely from 11 to NN, but the exact number of each room was unknown until she entered. She discovered that the treasure was hidden in room KK.

Given her remaining stamina, it was difficult for Alice to check all the rooms. However, Alice had a secret strategy to overcome this situation: binary search. Alice had successfully applied binary search to various challenges before. With her last ounce of strength, she decided to use binary search to find room KK.

Specifically, she followed these steps:

  • Initialize variables ll and rr with l=0l = 0 and r=N+1r = N + 1.
  • Repeat steps 1 to 3 as follows:
    1. If l+1=rl + 1 = r, stop the operation as she has not found room KK.
    2. Set m=l+r2m = \left\lfloor \frac{l + r}{2} \right\rfloor. Enter the room positioned mm-th from the left, check its number, and let this number be xx.
    3. If x=Kx = K, stop the operation as she has found room KK. If x<Kx < K, update ll to mm. If x>Kx > K, update rr to mm.

There are N!N! possible mappings between rooms and numbers. You need to determine the number of mappings for which Alice can successfully find room KK using the above procedure, modulo 998,244,353998,244,353.

Given TT test cases, compute the answer for each.

输入格式

The input is given in the following format:

$$\begin{aligned} &T \\ &\text{case}_1 \\ &\text{case}_2 \\ &\vdots \\ &\text{case}_T \end{aligned} $$

Here, casei\text{case}_i denotes the ii-th test case.

Each test case is given in the following format:

N KN \ K
  • 1T100,0001 \leq T \leq 100,000
  • 3N1063 \leq N \leq 10^6
  • 1KN1 \leq K \leq N
  • All input values are integers.

输出格式

Output TT lines. On the ii-th line, output the answer for the ii-th test case.

5
3 1
4 2
5 4
10 5
1000000 314159
4
12
66
1192320
853363991