結果

問題 No.789 範囲の合計
ユーザー はむ吉🐹はむ吉🐹
提出日時 2019-02-08 22:42:02
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 847 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 86,820 KB
実行使用メモリ 843,628 KB
最終ジャッジ日時 2023-09-14 03:52:04
合計ジャッジ時間 4,742 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N = 100000000


class FenwickTree(object):
 
    def __init__(self, num_elems):
        self.num_elems = num_elems
        self.data = [0 for _ in range(num_elems)]
 
    def sum_to(self, end):
        s = 0
        i = end - 1
        while i >= 0:
            s += self.data[i]
            i = (i & (i + 1)) - 1
        return s
 
    def sum_range(self, start, end):
        return self.sum_to(end) - self.sum_to(start)
 
    def add(self, idx, x):
        while idx < self.num_elems:
            self.data[idx] += x
            idx |= idx + 1


def main():
    ans = 0
    n = int(input())
    ft = FenwickTree(N)
    for _ in range(n):
        q, x, y = (int(z) for z in input().split())
        if q == 0:
            ft.add(x, y)
        else:
            ans += ft.sum_range(x, y + 1)
    print(ans)


if __name__ == "__main__":
    main()
0