結果

問題 No.2568 列辞書順列列
ユーザー mymelochanmymelochan
提出日時 2023-12-02 16:14:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 239 ms / 3,000 ms
コード長 945 bytes
コンパイル時間 621 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 119,628 KB
最終ジャッジ日時 2023-12-02 16:14:19
合計ジャッジ時間 8,281 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,720 KB
testcase_01 AC 44 ms
55,720 KB
testcase_02 AC 128 ms
86,888 KB
testcase_03 AC 131 ms
86,760 KB
testcase_04 AC 195 ms
119,628 KB
testcase_05 AC 195 ms
119,628 KB
testcase_06 AC 208 ms
119,628 KB
testcase_07 AC 191 ms
119,628 KB
testcase_08 AC 186 ms
119,628 KB
testcase_09 AC 199 ms
119,392 KB
testcase_10 AC 194 ms
119,392 KB
testcase_11 AC 186 ms
119,392 KB
testcase_12 AC 205 ms
119,392 KB
testcase_13 AC 209 ms
119,392 KB
testcase_14 AC 205 ms
119,392 KB
testcase_15 AC 207 ms
119,392 KB
testcase_16 AC 239 ms
119,392 KB
testcase_17 AC 192 ms
119,396 KB
testcase_18 AC 196 ms
119,396 KB
testcase_19 AC 197 ms
119,392 KB
testcase_20 AC 198 ms
119,392 KB
testcase_21 AC 225 ms
119,392 KB
testcase_22 AC 188 ms
119,392 KB
testcase_23 AC 181 ms
119,392 KB
testcase_24 AC 182 ms
119,392 KB
testcase_25 AC 185 ms
119,392 KB
testcase_26 AC 213 ms
119,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#############################################################

import sys
sys.setrecursionlimit(10**7)

from heapq import heappop,heappush
from collections import deque,defaultdict,Counter
from bisect import bisect_left, bisect_right
from itertools import product,combinations,permutations
from math import sin,cos
#from math import isqrt #DO NOT USE PyPy

ipt = sys.stdin.readline
iin = lambda :int(ipt())
lmin = lambda :list(map(int,ipt().split()))

MOD = 998244353
#############################################################

N,M,Q = lmin()
A = lmin()
query = [lmin() for _ in range(Q)]

p = [1]
ip = [1]

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

B = [0]*N
for i in range(N-1,-1,-1):
    B[i] = (A[i]-1)*p[N-1-i]%MOD

S = [0]*(N+1)
S[-1] = 1
for i in range(N-1,-1,-1):
    S[i] = (S[i+1]+B[i])%MOD

for l,r in query:
    ans = (S[l-1]-S[r])%MOD*ip[N-r]%MOD
    print((ans+1)%MOD)
0