結果

問題 No.2568 列辞書順列列
ユーザー 👑 timitimi
提出日時 2023-12-02 16:20:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 468 ms / 3,000 ms
コード長 727 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 146,168 KB
最終ジャッジ日時 2023-12-02 16:20:31
合計ジャッジ時間 13,006 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,460 KB
testcase_01 AC 32 ms
53,460 KB
testcase_02 AC 269 ms
76,760 KB
testcase_03 AC 289 ms
76,760 KB
testcase_04 AC 409 ms
146,168 KB
testcase_05 AC 402 ms
146,168 KB
testcase_06 AC 428 ms
146,168 KB
testcase_07 AC 396 ms
146,168 KB
testcase_08 AC 394 ms
146,168 KB
testcase_09 AC 406 ms
134,896 KB
testcase_10 AC 390 ms
134,896 KB
testcase_11 AC 384 ms
134,896 KB
testcase_12 AC 460 ms
134,896 KB
testcase_13 AC 436 ms
134,896 KB
testcase_14 AC 468 ms
134,896 KB
testcase_15 AC 435 ms
134,896 KB
testcase_16 AC 435 ms
134,896 KB
testcase_17 AC 429 ms
134,896 KB
testcase_18 AC 445 ms
134,896 KB
testcase_19 AC 415 ms
134,896 KB
testcase_20 AC 413 ms
134,896 KB
testcase_21 AC 418 ms
134,896 KB
testcase_22 AC 408 ms
134,896 KB
testcase_23 AC 414 ms
134,896 KB
testcase_24 AC 422 ms
134,896 KB
testcase_25 AC 441 ms
134,896 KB
testcase_26 AC 413 ms
134,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M,Q=map(int, input().split())
A=list(map(int, input().split()))
mod=998244353
B=[1];BB=[1]
for i in range(N-1):
  B.append(B[-1]*M%mod) 
  BB.append(BB[-1]*M%mod) 
B=B[::-1]
C=[]
for i in range(N):
  C.append((A[i]-1)*B[i]%mod)

D=[0]
for c in C:
  D.append(D[-1]+c)

def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

for _ in range(Q):
  l,r=map(int, input().split())
  ans=(D[r]-D[l-1])*modinv(BB[N-r],mod)%mod+1
  ans%=mod
  print(ans)
0