結果

問題 No.789 範囲の合計
ユーザー amyuamyu
提出日時 2019-07-04 20:07:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 405 ms / 1,000 ms
コード長 762 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 81,620 KB
実行使用メモリ 100,164 KB
最終ジャッジ日時 2023-10-19 10:35:26
合計ジャッジ時間 5,044 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
57,548 KB
testcase_01 AC 42 ms
57,548 KB
testcase_02 AC 382 ms
98,816 KB
testcase_03 AC 333 ms
98,708 KB
testcase_04 AC 385 ms
98,916 KB
testcase_05 AC 315 ms
98,916 KB
testcase_06 AC 324 ms
98,512 KB
testcase_07 AC 299 ms
97,948 KB
testcase_08 AC 284 ms
97,516 KB
testcase_09 AC 286 ms
97,808 KB
testcase_10 AC 405 ms
100,164 KB
testcase_11 AC 364 ms
98,612 KB
testcase_12 AC 362 ms
98,584 KB
testcase_13 AC 42 ms
57,548 KB
testcase_14 AC 41 ms
57,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left
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)
X.sort()
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 qsum(l,r):
    L=l+No-1
    R=r+No-1
    s=0
    while L<=R:
        if R&1:
            s+=tree[R]
            R-=2
        else:
            R-=1
        if L&1:
            L-=1
        else:
            s+=tree[L]
        L>>=1;R>>=1
    return s
ans=0
for i in l:
    a,x,y=i
    if a:
        x=bisect_left(X,x)
        y=bisect_left(X,y)
        ans+=qsum(x,y)
    else:
        x=bisect_left(X,x)
        add(x,y)
print(ans)
0