結果

問題 No.2571 列辞書順列
ユーザー AngrySadEightAngrySadEight
提出日時 2023-12-01 08:05:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 574 ms / 3,000 ms
コード長 1,594 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 97,172 KB
最終ジャッジ日時 2023-12-09 18:08:46
合計ジャッジ時間 17,178 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 335 ms
77,904 KB
testcase_03 AC 320 ms
78,132 KB
testcase_04 AC 404 ms
85,148 KB
testcase_05 AC 405 ms
85,148 KB
testcase_06 AC 562 ms
97,172 KB
testcase_07 AC 574 ms
97,172 KB
testcase_08 AC 449 ms
97,172 KB
testcase_09 AC 447 ms
97,172 KB
testcase_10 AC 553 ms
97,172 KB
testcase_11 AC 557 ms
97,172 KB
testcase_12 AC 571 ms
97,172 KB
testcase_13 AC 562 ms
97,172 KB
testcase_14 AC 564 ms
97,172 KB
testcase_15 AC 562 ms
97,172 KB
testcase_16 AC 558 ms
97,172 KB
testcase_17 AC 561 ms
97,172 KB
testcase_18 AC 566 ms
97,172 KB
testcase_19 AC 567 ms
97,172 KB
testcase_20 AC 551 ms
97,172 KB
testcase_21 AC 563 ms
97,172 KB
testcase_22 AC 554 ms
97,172 KB
testcase_23 AC 546 ms
97,172 KB
testcase_24 AC 562 ms
97,172 KB
testcase_25 AC 545 ms
97,172 KB
testcase_26 AC 557 ms
97,172 KB
testcase_27 AC 562 ms
97,172 KB
testcase_28 AC 556 ms
97,172 KB
testcase_29 AC 553 ms
97,172 KB
testcase_30 AC 35 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353


class BIT:
    def __init__(self, n):
        self.n = n
        self.lst = [0 for _ in range(n + 1)]

    def add(self, p, x):
        while True:
            if p > self.n:
                break
            self.lst[p] += x
            self.lst[p] %= 998244353
            p += (p & -p)

    def sum(self, p):
        res = 0
        while True:
            if p <= 0:
                break
            res += self.lst[p]
            res %= 998244353
            p -= (p & -p)
        return res

    def get(self, p):
        return (self.sum(p) - self.sum(p - 1)) % 998244353


N, M, K, Q = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
    A[i] -= 1

inv_m = pow(M - 1, mod - 2, mod)
pow_m = [1]
for i in range(N):
    add_res = (pow_m[-1] * M) % mod
    pow_m.append(add_res)

bit1 = BIT(N)
bit2 = BIT(N)

for i in range(N):
    bit1.add(i + 1, (pow(M, K - i, mod) * A[i]) % mod)
    bit2.add(i + 1, A[i])

for i in range(Q):
    t, l, r = map(int, input().split())
    if t == 1:
        # do nothing
        l -= 1
        r -= 1
        ans = (r - l + 1)
        prd1 = bit1.sum(r + 1) - bit1.sum(l)
        prd1 = (prd1 * pow_m[l]) % mod
        prd2 = bit2.sum(r + 1) - bit2.sum(l)
        sums = (prd1 - prd2) % mod
        sums = (sums * inv_m) % mod
        ans = (ans + sums) % mod
        print(ans)
    else:
        l -= 1
        r -= 1
        now_bit1 = bit1.get(l + 1)
        now_bit2 = bit2.get(l + 1)
        bit1.add(l + 1, (-now_bit1 + pow(M, K - l, mod) * r) % mod)
        bit2.add(l + 1, (-now_bit2 + r) % mod)
0