結果

問題 No.789 範囲の合計
ユーザー mkawa2mkawa2
提出日時 2021-02-12 08:59:33
言語 PyPy3
(7.3.15)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,563 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 147,792 KB
最終ジャッジ日時 2023-09-26 07:42:38
合計ジャッジ時間 4,809 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
72,936 KB
testcase_01 AC 71 ms
72,512 KB
testcase_02 MLE -
testcase_03 AC 173 ms
89,348 KB
testcase_04 MLE -
testcase_05 MLE -
testcase_06 MLE -
testcase_07 AC 170 ms
89,876 KB
testcase_08 AC 232 ms
112,472 KB
testcase_09 AC 218 ms
109,476 KB
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 AC 71 ms
72,532 KB
testcase_14 AC 72 ms
72,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def MI(): return map(int, sys.stdin.buffer.readline().split())
def MI1(): return map(int1, sys.stdin.buffer.readline().split())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
inf = 10**16
# md = 998244353
md = 10**9+7

class BitSum:
    def __init__(self, n):
        self.n = n+1
        self.table = [0]*self.n

    def add(self, i, x):
        i += 1
        while i < self.n:
            self.table[i] += x
            i += i & -i

    # [0,i]の和
    def sum(self, i):
        i += 1
        res = 0
        while i > 0:
            res += self.table[i]
            i -= i & -i
        return res

    # [l,r)の和
    def sumlr(self, l, r):
        if l >= r: return 0
        if l == 0: return self.sum(r-1)
        return self.sum(r-1)-self.sum(l-1)

mx=200005
n=II()
q=LLI(n)

xx=set()
for t,x,y in q:
    if t:
        xx.add(x)
        xx.add(y)
    else:
        xx.add(x)
enc={a:i for i,a in enumerate(sorted(xx))}

bit=BitSum(mx)
ans=0
for t,x,y in q:
    if t:
        l,r=enc[x],enc[y]+1
        ans+=bit.sumlr(l,r)
    else:
        x=enc[x]
        bit.add(x,y)

print(ans)
0