結果

問題 No.2568 列辞書順列列
コンテスト
ユーザー OblongVeil4309
提出日時 2026-11-12 11:38:42
言語 PyPy3
(8.0.1 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 274 ms / 3,000 ms
+ 350µs
コード長 540 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 87 ms
コンパイル使用メモリ 64,584 KB
実行使用メモリ 92,704 KB
最終ジャッジ日時 2026-11-12 11:39:12
合計ジャッジ時間 12,696 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from itertools import accumulate

N, M, Q = (int(x) for x in input().split())
A = list(map(int, input().split()))
mem = []
mod = 998244353
for num, i in enumerate(A):
    mem.append((i-1)*pow(M, N-num-1, mod))
mem = list(accumulate(mem))
ans = []
for _ in range(Q):
    l, r = (int(x) for x in input().split())
    l, r = l-1, r-1
    if l == 0:
        ans.append((mem[r]*pow(pow(M, N-r-1, mod), mod-2, mod))%mod)
    else:
        ans.append(((mem[r]-mem[l-1])*pow(pow(M, N-r-1, mod), mod-2, mod))%mod)

for i in ans:
    print((i+1)%mod)
0