Distance Permutation

시간 제한5초메모리 제한1024 MB

요약
걷기 과정에서 만들어질 수 있는 1..N의 순열 가운데 첫 값이 [L, R]에 들어가는 순열의 개수를 센다.
난이도

어려움10점 중 8점

유형
조합론, 동적 계획법, 수학
정답자
아직 제출이 없습니다

문제

You construct a permutation P=(P_1,P_2,…,P_105)P = (P\_1, P\_2, \dots , P\_{10^5}) of length 10510^5 in the following way.

The number line has points 1,2,…,1051, 2, \dots, 10^5. The distance between points ii and jj is ∣i−j∣|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 NN, LL, RR. Let the sequence created by removing elements larger than NN from PP be P′=(P′_1,P′_2,…,P′_N)P' = (P'\_1, P'\_2, \dots , P'\_N). Among the possible permutations of P′P', answer the number of permutations in which P′_1P'\_1 is greater than or equal to LL and less than or equal to RR with 998244353998244353.

입력

KK QQ

query_1\text{query}\_1

⋮\vdots

query_Q\text{query}\_Q

query_i\text{query}\_i represents the ii-th query.

Each query is given in the following format.

NN LL RR

출력

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

제한

  • All inputs consist of integers.
  • 1≤Q≤2×1051 \le Q \le 2 \times 10^5
  • 1≤K≤1051 \le K \le 10^5
  • 1≤N≤1051 \le N \le 10^5
  • 1≤L≤R≤N1 \le L \le R \le N

힌트

In Sample Input 1, There are four possible sequences as P′P' 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)

예제2

  1. 예제 1

    입력
    2 4
    4 1 1
    3 1 3
    10 2 7
    1 1 1
    
    예상 출력
    4
    6
    140172
    1
    
  2. 예제 2

    입력
    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