結果

問題 No.789 範囲の合計
ユーザー ああいいああいい
提出日時 2022-06-12 19:02:49
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,346 bytes
コンパイル時間 1,173 ms
コンパイル使用メモリ 81,576 KB
実行使用メモリ 133,980 KB
最終ジャッジ日時 2023-10-24 13:08:02
合計ジャッジ時間 5,999 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,432 KB
testcase_01 AC 37 ms
53,432 KB
testcase_02 AC 312 ms
127,308 KB
testcase_03 AC 172 ms
88,916 KB
testcase_04 AC 316 ms
126,684 KB
testcase_05 MLE -
testcase_06 AC 295 ms
127,308 KB
testcase_07 AC 172 ms
89,084 KB
testcase_08 AC 228 ms
106,220 KB
testcase_09 AC 236 ms
104,044 KB
testcase_10 MLE -
testcase_11 AC 291 ms
123,592 KB
testcase_12 AC 289 ms
123,540 KB
testcase_13 AC 37 ms
53,436 KB
testcase_14 AC 36 ms
53,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#BIT plus ver
class BITplus:
    def __init__(self,N):
        self.N = N
        self.bit = [0] * (self.N+1)
    def add(self,i,x):
        while i <= self.N:
            self.bit[i] += x
            i += i & -i
    def fold(self,i):
        ans = 0
        while i > 0:
            ans += self.bit[i]
            i -= i & -i
        return ans
    def lb(self,w):
        if w <= 0:return 0
        x = 0
        k = 1
        while k <= self.N:
            k <<= 1
        k >>= 1
        while k:
            if x + k <= self.N and self.bit[x+k] < w:
                w -= self.bit[x+k]
                x += k
            k >>= 1
        return x + 1

    #サイズ N の配列をいれる
    def build(self,seq):
        bit = self.bit
        N = self.N
        for i in range(N):
            bit[i+1] = seq[i]
        for i in range(1,N+1):
            if i + (i & -1) <= N:
                bit[i + (i & -i)] += bit[i]

query = []
s = set()
n = int(input())
for _ in range(n):
    a,b,c = map(int,input().split())
    query.append((a,b,c))
    if a == 0:
        s.add(b)
    else:
        s.add(b)
        s.add(c)
rD = sorted(s)
D = {v:i + 1 for i,v in enumerate(rD)}
N = len(D)
bit = BITplus(N)
ans = 0
for a,b,c in query:
    if a == 0:
        bit.add(D[b],c)
    else:
        ans += bit.fold(D[c]) - bit.fold(D[b] - 1)
print(ans)
0