結果

問題 No.2273 一点乗除区間積
ユーザー ecotteaecottea
提出日時 2023-03-09 04:32:27
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,369 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 81,840 KB
実行使用メモリ 135,076 KB
最終ジャッジ日時 2023-10-18 06:10:32
合計ジャッジ時間 8,021 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,560 KB
testcase_01 AC 38 ms
53,560 KB
testcase_02 AC 38 ms
53,560 KB
testcase_03 AC 38 ms
53,560 KB
testcase_04 AC 38 ms
53,560 KB
testcase_05 AC 37 ms
53,560 KB
testcase_06 AC 37 ms
53,560 KB
testcase_07 AC 38 ms
53,560 KB
testcase_08 AC 38 ms
53,560 KB
testcase_09 AC 39 ms
53,560 KB
testcase_10 AC 39 ms
53,560 KB
testcase_11 AC 39 ms
53,560 KB
testcase_12 AC 38 ms
53,560 KB
testcase_13 AC 38 ms
53,560 KB
testcase_14 AC 39 ms
53,560 KB
testcase_15 AC 39 ms
53,560 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegmentTree:
    def __init__(self, ini, op, e):
        self.n = len(ini)
        self.op = op
        self.e = e
        self.v = [e] * (2 * self.n)
    
        for i in range(self.n):
            self.v[self.n + i] = ini[i]
  
        for i in range(self.n - 1, 0, -1):
            self.v[i] = op(self.v[2 * i], self.v[2 * i + 1])

    def set(self, i, x):
        i += self.n
        self.v[i] = x
        while i > 1:
            i >>= 1
            self.v[i] = self.op(self.v[2 * i], self.v[2 * i + 1])

    def prod(self, l, r):
        resl = self.e
        resr = self.e

        l += self.n
        r += self.n
        while l < r:
            if l & 1:
                resl = self.op(resl, self.v[l])
                l += 1
            if r & 1:
                resr = self.op(self.v[r - 1], resr)
            l >>= 1
            r >>= 1
        return self.op(resl, resr)
    
    def get(self, i):
        return self.v[i + self.n]
    
    def dump(self):
        print(self.v[self.n:])

def op(x, y):
    return x * y

e = 1


N, B, Q = map(int, input().split())

A = list(map(int, input().split()))

seg = SegmentTree(A, op, e)

for _ in range(Q):
    j, m, l, r = map(int, input().split())

    x = seg.get(j)

    if x % B == 0 and m == B:
        x //= B
    else:
        x *= m
    
    seg.set(j, x)
    
    print(seg.prod(l, r + 1) % B)
0