結果

問題 No.789 範囲の合計
ユーザー kohei2019kohei2019
提出日時 2022-07-29 01:03:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 770 ms / 1,000 ms
コード長 902 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 11,032 KB
実行使用メモリ 47,656 KB
最終ジャッジ日時 2023-09-25 19:41:58
合計ジャッジ時間 7,877 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,300 KB
testcase_01 AC 16 ms
8,152 KB
testcase_02 AC 729 ms
40,608 KB
testcase_03 AC 371 ms
16,612 KB
testcase_04 AC 704 ms
40,284 KB
testcase_05 AC 643 ms
40,096 KB
testcase_06 AC 693 ms
40,348 KB
testcase_07 AC 348 ms
16,772 KB
testcase_08 AC 527 ms
29,404 KB
testcase_09 AC 500 ms
28,896 KB
testcase_10 AC 770 ms
47,656 KB
testcase_11 AC 646 ms
40,024 KB
testcase_12 AC 633 ms
40,020 KB
testcase_13 AC 16 ms
8,308 KB
testcase_14 AC 16 ms
8,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT():
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    def add(self, i, x):
        # assert i > 0
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    def get(self, i, j):
        return self.sum(j) - self.sum(i)

def main():
    N = int(input())
    lsQ = []
    ss = set([0])
    for i in range(N):
        a,x,y = map(int,input().split())
        lsQ.append((a,x,y))
        if a == 0:
            ss.add(x)
        else:
            ss.add(x)
            ss.add(y)
    dic = {x:i+1 for i,x in enumerate(sorted(ss))}
    ans = 0
    BI = BIT(len(ss))
    for a,x,y in lsQ:
        if a == 0:
            BI.add(dic[x],y)
        else:
            ans += BI.get(dic[x]-1, dic[y])
    print(ans)
main()
0