結果

問題 No.789 範囲の合計
ユーザー amyuamyu
提出日時 2019-07-04 19:50:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 702 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 12,000 KB
実行使用メモリ 33,128 KB
最終ジャッジ日時 2023-10-19 10:33:41
合計ジャッジ時間 13,362 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
14,368 KB
testcase_01 AC 42 ms
14,368 KB
testcase_02 TLE -
testcase_03 AC 852 ms
23,980 KB
testcase_04 TLE -
testcase_05 AC 964 ms
31,848 KB
testcase_06 AC 998 ms
32,548 KB
testcase_07 AC 781 ms
23,940 KB
testcase_08 AC 857 ms
30,760 KB
testcase_09 AC 812 ms
30,392 KB
testcase_10 TLE -
testcase_11 AC 961 ms
31,932 KB
testcase_12 AC 940 ms
31,976 KB
testcase_13 AC 42 ms
14,368 KB
testcase_14 AC 40 ms
14,368 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