結果

問題 No.2568 列辞書順列列
ユーザー Nichi10pNichi10p
提出日時 2023-12-02 16:58:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,411 ms / 3,000 ms
コード長 493 bytes
コンパイル時間 127 ms
コンパイル使用メモリ 11,776 KB
実行使用メモリ 42,736 KB
最終ジャッジ日時 2023-12-02 16:58:39
合計ジャッジ時間 32,776 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
9,984 KB
testcase_01 AC 29 ms
9,984 KB
testcase_02 AC 763 ms
9,984 KB
testcase_03 AC 775 ms
9,984 KB
testcase_04 AC 1,232 ms
36,388 KB
testcase_05 AC 1,217 ms
36,380 KB
testcase_06 AC 1,207 ms
36,384 KB
testcase_07 AC 1,256 ms
36,380 KB
testcase_08 AC 1,259 ms
36,380 KB
testcase_09 AC 1,187 ms
42,736 KB
testcase_10 AC 1,174 ms
42,736 KB
testcase_11 AC 1,186 ms
42,736 KB
testcase_12 AC 1,377 ms
42,736 KB
testcase_13 AC 1,406 ms
42,736 KB
testcase_14 AC 1,374 ms
42,736 KB
testcase_15 AC 1,362 ms
42,736 KB
testcase_16 AC 1,411 ms
42,736 KB
testcase_17 AC 1,220 ms
42,736 KB
testcase_18 AC 1,214 ms
42,736 KB
testcase_19 AC 1,230 ms
42,736 KB
testcase_20 AC 1,250 ms
42,736 KB
testcase_21 AC 1,215 ms
42,736 KB
testcase_22 AC 1,213 ms
42,724 KB
testcase_23 AC 1,205 ms
42,736 KB
testcase_24 AC 1,174 ms
42,736 KB
testcase_25 AC 1,204 ms
42,736 KB
testcase_26 AC 1,204 ms
42,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import accumulate

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

# a b c d
# (a-1)*M*M*M (b-1)*M*M (c-1)*M (d-1)
P = [1]
for _ in range(1, N):
  P.append(P[-1] * M % MOD)
P.reverse()
S = tuple((a-1) * p % MOD for a, p in zip(A, P))
S = tuple(s % MOD for s in accumulate(S, initial=0))

for _ in range(Q):
  L, R = map(int, input().split())
  s = (S[R] - S[L-1]) % MOD
  d = pow(M, N-R, MOD)
  print((s * pow(d, MOD-2, MOD) + 1) % MOD)
0