結果

問題 No.2568 列辞書順列列
ユーザー ゼットゼット
提出日時 2023-12-21 00:54:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 447 ms / 3,000 ms
コード長 531 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 110,960 KB
最終ジャッジ日時 2023-12-21 00:54:55
合計ジャッジ時間 15,470 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 288 ms
76,008 KB
testcase_03 AC 288 ms
76,012 KB
testcase_04 AC 387 ms
108,384 KB
testcase_05 AC 413 ms
108,384 KB
testcase_06 AC 385 ms
108,384 KB
testcase_07 AC 385 ms
108,384 KB
testcase_08 AC 410 ms
108,384 KB
testcase_09 AC 403 ms
110,960 KB
testcase_10 AC 404 ms
110,960 KB
testcase_11 AC 427 ms
110,960 KB
testcase_12 AC 422 ms
110,960 KB
testcase_13 AC 431 ms
110,960 KB
testcase_14 AC 422 ms
110,960 KB
testcase_15 AC 418 ms
110,960 KB
testcase_16 AC 447 ms
110,960 KB
testcase_17 AC 401 ms
110,960 KB
testcase_18 AC 400 ms
110,960 KB
testcase_19 AC 422 ms
110,960 KB
testcase_20 AC 400 ms
110,960 KB
testcase_21 AC 399 ms
110,960 KB
testcase_22 AC 401 ms
110,960 KB
testcase_23 AC 399 ms
110,960 KB
testcase_24 AC 400 ms
110,960 KB
testcase_25 AC 404 ms
110,960 KB
testcase_26 AC 401 ms
110,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M,Q=map(int,input().split())
A=list(map(int,input().split()))
u=[1]*(N+1)
mod=998244353
v=[0]*(N+1)
for i in range(1,N+1):
  u[i]=u[i-1]*M
  u[i]%=mod
u2=[1]*(N+1)
for i in range(1,N+1):
  ans=1
  w=u[i]
  n=mod-2
  while n>0:
    if n&1:
      ans*=w
      ans%=mod
    w**=2
    w%=mod
    n//=2
  u2[i]=ans
for i in range(N-1,-1,-1):
  A[i]-=1
  v[i]=v[i+1]+A[i]*u[N-1-i]
  v[i]%=mod
for i in range(Q):
  l,r=map(int,input().split())
  l-=1
  r-=1
  ans=v[l]-v[r+1]
  ans%=mod
  ans*=u2[N-1-r]
  ans+=1
  ans%=mod
  print(ans)
0