結果

問題 No.789 範囲の合計
ユーザー amyuamyu
提出日時 2019-07-04 19:51:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 424 ms / 1,000 ms
コード長 702 bytes
コンパイル時間 989 ms
コンパイル使用メモリ 81,488 KB
実行使用メモリ 100,120 KB
最終ジャッジ日時 2023-10-19 10:33:56
合計ジャッジ時間 5,279 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
57,440 KB
testcase_01 AC 43 ms
57,440 KB
testcase_02 AC 419 ms
98,788 KB
testcase_03 AC 355 ms
98,640 KB
testcase_04 AC 413 ms
98,848 KB
testcase_05 AC 327 ms
98,856 KB
testcase_06 AC 333 ms
98,432 KB
testcase_07 AC 313 ms
97,972 KB
testcase_08 AC 286 ms
97,448 KB
testcase_09 AC 290 ms
97,744 KB
testcase_10 AC 424 ms
100,120 KB
testcase_11 AC 375 ms
98,556 KB
testcase_12 AC 363 ms
98,528 KB
testcase_13 AC 42 ms
57,440 KB
testcase_14 AC 42 ms
57,440 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 sum(l):
    if l<0:
        return 0
    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:
        x=bisect_left(X,x)-1
        y=bisect_left(X,y)
        ans+=sum(y)-sum(x)
    else:
        x=bisect_left(X,x)
        add(x,y)
print(ans)
0