結果

問題 No.789 範囲の合計
ユーザー amyuamyu
提出日時 2019-07-04 02:35:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 552 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 11,964 KB
実行使用メモリ 28,616 KB
最終ジャッジ日時 2023-10-17 15:15:22
合計ジャッジ時間 6,163 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 37 ms
14,080 KB
testcase_02 RE -
testcase_03 AC 686 ms
23,780 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 645 ms
23,828 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
l=[]
X=[]
for i in range(n):
    a,x,y=map(int,input().split())
    l.append((a,x,y))
    if a:
        X.append(x)
        X.append(y)
    else:
        X.append(x)
No=2**18
tree=[0]*(2*No)
def add(k,x):
    k+=No-1
    while k>=0:
        tree[k]+=x
        k=(k-1)//2
def sum(l):
    L=l+No-1
    s=0
    while L>0:
        if L&1:
            s+=tree[L]
            L=(L-2)//2
        else:
            L=(L-1)//2
    return s
ans=0
for i in l:
    a,x,y=i
    if a:
        ans+=sum(y)-sum(x-1)
    else:
        add(x,y)
print(ans)
0