結果

問題 No.2568 列辞書順列列
ユーザー けんぴんけんぴん
提出日時 2023-10-26 02:34:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 370 ms / 3,000 ms
コード長 775 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 81,788 KB
実行使用メモリ 132,408 KB
最終ジャッジ日時 2023-10-28 06:43:28
合計ジャッジ時間 11,014 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 38 ms
53,460 KB
testcase_02 AC 277 ms
75,912 KB
testcase_03 AC 273 ms
75,912 KB
testcase_04 AC 342 ms
132,408 KB
testcase_05 AC 339 ms
132,408 KB
testcase_06 AC 343 ms
132,408 KB
testcase_07 AC 341 ms
132,408 KB
testcase_08 AC 342 ms
132,408 KB
testcase_09 AC 353 ms
121,236 KB
testcase_10 AC 348 ms
121,236 KB
testcase_11 AC 354 ms
121,236 KB
testcase_12 AC 370 ms
121,236 KB
testcase_13 AC 365 ms
121,236 KB
testcase_14 AC 362 ms
121,236 KB
testcase_15 AC 368 ms
121,236 KB
testcase_16 AC 367 ms
121,236 KB
testcase_17 AC 343 ms
121,236 KB
testcase_18 AC 344 ms
121,236 KB
testcase_19 AC 341 ms
121,236 KB
testcase_20 AC 343 ms
121,236 KB
testcase_21 AC 353 ms
121,236 KB
testcase_22 AC 351 ms
121,236 KB
testcase_23 AC 351 ms
121,236 KB
testcase_24 AC 352 ms
121,236 KB
testcase_25 AC 349 ms
121,236 KB
testcase_26 AC 349 ms
121,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    mod = 998244353
    N,M,Q = map(int,input().split())
    assert 1 <= N <= 2*10**5
    assert 1 <= M <= 2*10**5
    assert 1 <= Q <= 2*10**5
    A = list(map(lambda x: int(x)-1, input().split()))
    for a in A:
        assert 0 <= a <= M-1
    acc_A = [0]
    e = 1
    for a in A[::-1]:
        acc_A.append((acc_A[-1] + a*e) % mod)
        e = (e * M) % mod
    # Mの逆元
    inv_M = pow(M, mod-2, mod)
    # Mのi乗の逆元を前計算
    inv_M_list = [1]
    for i in range(1, N+1):
        inv_M_list.append((inv_M_list[-1] * inv_M) % mod)
    for _ in range(Q):
        l,r = map(int, input().split())
        assert 1 <= l <= r <= N
        print(((acc_A[-l] - acc_A[-r-1]) * inv_M_list[N-r] + 1) % mod)
    
if __name__ == "__main__":
    main()
0