#P15714. [JAG 2023 Summer Camp #2] Distance Permutation

[JAG 2023 Summer Camp #2] Distance Permutation

题目描述

You construct a permutation P=(P1,P2,,P105)P = (P_1, P_2, \ldots, P_{10^5}) of length 10510^5 in the following way.

The number line has points 1,2,,1051, 2, \ldots, 10^5. The distance between points ii and jj is ij|i - j|. Also, there is a sequence PP that is initially empty. Repeat the following operations from any point until the length of PP is 10510^5.

  • Let xx be the number corresponding to the current point. If xx is not in PP, add xx to the end of PP. Next, move to one of the points whose distance is less than or equal to KK.

Answer the following QQ queries.

  • You are given integers N,L,RN, L, R. Let the sequence created by removing elements larger than NN from PP be P=(P1,P2,,PN)P' = (P'_1, P'_2, \ldots, P'_N). Among the possible permutations of PP', answer the number of permutations in which P1P'_1 is greater than or equal to LL and less than or equal to RR with mod 998244353998244353.

输入格式

$$\begin{aligned} &K \ Q \\ &query_1 \\ &\vdots \\ &query_Q \end{aligned} $$

queryiquery_i represents the ii-th query.

Each query is given in the following format.

N L RN \ L \ R

The input satisfies the following constraints.

  • All inputs consist of integers.
  • 1Q2×1051 \leq Q \leq 2 \times 10^5
  • 1K1051 \leq K \leq 10^5
  • 1N1051 \leq N \leq 10^5
  • 1LRN1 \leq L \leq R \leq N

输出格式

Output QQ lines. On the ii-th line, output the answer of the ii-th query.

2 4
4 1 1
3 1 3
10 2 7
1 1 1
4
6
140172
1
314 6
60522 7560 25373
79445 26896 78962
33447 12441 21469
47202 17227 32455
63982 13450 41311
2156 1226 2148
925500464
455690352
567782656
893053639
942918900
458845228

提示

In Sample Input 1, There are four possible sequences as PP' in the first query.

  • (1,2,3,4)(1, 2, 3, 4)
  • (1,2,4,3)(1, 2, 4, 3)
  • (1,3,2,4)(1, 3, 2, 4)
  • (1,3,4,2)(1, 3, 4, 2)