結果

問題 No.789 範囲の合計
コンテスト
ユーザー Fuyuru
提出日時 2024-02-16 17:58:20
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
MLE  
実行時間 -
コード長 900 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 280 ms
コンパイル使用メモリ 84,908 KB
実行使用メモリ 174,516 KB
最終ジャッジ日時 2026-04-15 08:06:24
合計ジャッジ時間 4,286 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 MLE * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import defaultdict
import sys
input = sys.stdin.readline
#print = sys.stdout.write
class BIT:
    def __init__(self,N):
        self.N = N
        self.data = defaultdict(lambda: 0)
    def build(self,A):
        for i in range(1,self.N+1):
            self.data[i] += A[i-1]
            if i+(i&-i) <= self.N:
                self.data[i+(i&-i)] += self.data[i]
    def add(self,i,x):
        i += 1
        while i <= self.N:
            self.data[i] += x
            i += i&-i
    def fold(self,l,r):
        res = 0
        while r > 0:
            res += self.data[r]
            r -= r&-r
        while l > 0:
            res -= self.data[l]
            l -= l&-l
        return res


bit = BIT(1000000001)
Q = int(input())
ans = 0
for _ in range(Q):
    op,x,y = map(int,input().split())
    if op == 0:
        bit.add(x,y)
    else:
        ans += bit.fold(x,y+1)
print(ans)
0