結果

問題 No.2568 列辞書順列列
ユーザー sasa8uyauya
提出日時 2024-09-06 19:24:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 364 ms / 3,000 ms
コード長 363 bytes
コンパイル時間 607 ms
コンパイル使用メモリ 82,140 KB
実行使用メモリ 109,116 KB
最終ジャッジ日時 2024-09-06 19:24:53
合計ジャッジ時間 11,699 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m,q=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
	a[i]-=1
M=998244353
B=m
P=[1,B]
R=[1,pow(B,M-2,M)]
for i in range(2,n):
	P+=[P[-1]*P[1]%M]
	R+=[R[-1]*R[1]%M]
h=[0]*(n+1)
for i in reversed(range(n)):
	h[i]=(a[i]*P[n-1-i]+h[i+1])%M
for i in range(q):
	l,r=map(int,input().split())
	l-=1
	r-=1
	print(((h[l]-h[r+1])*R[n-1-r]+1)%M)
0