結果

問題 No.2568 列辞書順列列
ユーザー torippytorippy
提出日時 2023-12-02 16:34:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 393 ms / 3,000 ms
コード長 525 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 119,280 KB
最終ジャッジ日時 2023-12-02 16:34:57
合計ジャッジ時間 11,644 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,332 KB
testcase_01 AC 37 ms
53,332 KB
testcase_02 AC 129 ms
82,532 KB
testcase_03 AC 129 ms
82,532 KB
testcase_04 AC 367 ms
116,752 KB
testcase_05 AC 365 ms
116,752 KB
testcase_06 AC 368 ms
116,752 KB
testcase_07 AC 361 ms
116,752 KB
testcase_08 AC 364 ms
116,752 KB
testcase_09 AC 381 ms
119,280 KB
testcase_10 AC 376 ms
119,280 KB
testcase_11 AC 377 ms
119,280 KB
testcase_12 AC 384 ms
119,280 KB
testcase_13 AC 381 ms
119,280 KB
testcase_14 AC 384 ms
119,280 KB
testcase_15 AC 393 ms
119,280 KB
testcase_16 AC 387 ms
119,280 KB
testcase_17 AC 373 ms
119,280 KB
testcase_18 AC 373 ms
119,280 KB
testcase_19 AC 377 ms
119,280 KB
testcase_20 AC 376 ms
119,280 KB
testcase_21 AC 374 ms
119,280 KB
testcase_22 AC 374 ms
119,280 KB
testcase_23 AC 374 ms
119,280 KB
testcase_24 AC 371 ms
119,280 KB
testcase_25 AC 376 ms
119,280 KB
testcase_26 AC 377 ms
119,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M, Q = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353

ls = []
rs = []

invs = []
p = 1
for i in range(N+1):
    invs.append(pow(p, MOD-2, MOD))
    p = (p*M) % MOD

for _ in range(Q):
    l, r = map(int, input().split())
    ls.append(l)
    rs.append(r)

acc = [0]
p = 1
for i in range(N):
    acc.append((acc[-1] + (A[N-i-1]-1)*p) % MOD)
    p = (p*M) % MOD

for i in range(Q):
    l, r, = ls[i], rs[i]
    r = N-r
    l = N-l+1

    ans = ((acc[l]-acc[r])*invs[r]+1) % MOD
    print(ans)
0