結果

問題 No.789 範囲の合計
ユーザー 👑 rin204rin204
提出日時 2022-09-30 22:57:23
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,933 bytes
コンパイル時間 1,521 ms
コンパイル使用メモリ 86,580 KB
実行使用メモリ 137,980 KB
最終ジャッジ日時 2023-08-24 16:31:45
合計ジャッジ時間 6,862 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,136 KB
testcase_01 AC 73 ms
71,416 KB
testcase_02 MLE -
testcase_03 AC 226 ms
90,984 KB
testcase_04 AC 384 ms
119,720 KB
testcase_05 AC 368 ms
124,300 KB
testcase_06 MLE -
testcase_07 AC 220 ms
90,976 KB
testcase_08 AC 279 ms
109,160 KB
testcase_09 AC 288 ms
105,340 KB
testcase_10 MLE -
testcase_11 MLE -
testcase_12 AC 790 ms
127,924 KB
testcase_13 AC 79 ms
71,496 KB
testcase_14 AC 79 ms
71,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegTree:
    def __init__(self, n, e, ope, lst=[]):
        self.N0 = 2 ** (n - 1).bit_length()
        self.e = e
        self.ope = ope
        self.data = [e] * (2 * self.N0)
        if lst:
            for i in range(n):
                self.data[self.N0 + i] = lst[i]
            for i in range(self.N0 - 1, 0, -1):
                self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
    
    def build(self):
        for i in range(self.N0 - 1, 0, -1):
            self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
                
    def update(self, i, x): #a_iの値をxに更新
        i += self.N0
        self.data[i] = x
        while i > 1:
            i >>= 1
            self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
    
    def add(self, i, x):
        self.update(i, x + self.get(i))

    def set(self, i, x):
        self.data[self.N0 + i] = x
    
    def query(self, l, r): #区間[l, r)での演算結果
        if r <= l:
            return self.e
        lres = self.e
        rres = self.e
        l += self.N0
        r += self.N0
        while l < r:
            if l & 1:
                lres = self.ope(lres, self.data[l])
                l += 1
            if r & 1:
                r -= 1
                rres = self.ope(self.data[r], rres)
            l >>= 1
            r >>= 1
        return self.ope(lres, rres)
    
    def get(self, i): #a_iの値を返す
        return self.data[self.N0 + i]

n = int(input())
query = []
X = set()
for _ in range(n):
    t, x, y = map(int, input().split())
    X.add(x)
    if t == 1:
        y += 1
        X.add(y)
    query.append((t, x, y))

n = len(X)
lst = sorted(X)
dic = {l:i for i, l in enumerate(lst)}
seg = SegTree(n, 0, lambda x, y: x + y)

ans = 0
for t, x, y in query:
    x = dic[x]
    if t == 0:
        seg.add(x, y)
    else:
        y = dic[y]
        ans += seg.query(x, y)
print(ans)
0