結果
問題 |
No.789 範囲の合計
|
ユーザー |
![]() |
提出日時 | 2025-03-29 21:01:19 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 998 bytes |
コンパイル時間 | 406 ms |
コンパイル使用メモリ | 82,320 KB |
実行使用メモリ | 202,112 KB |
最終ジャッジ日時 | 2025-03-29 21:01:25 |
合計ジャッジ時間 | 6,509 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 RE * 2 MLE * 10 |
ソースコード
class DynamicBIT: from collections import defaultdict def __init__(self, n): self.n = n + 1 #self.d = self.defaultdict(int) self.d = [0] * self.n def add(self, i, x): i += 1 while i <= self.n: self.d[i] += x i += i & -i def _sum(self, i): res = 0 while i > 0: res += self.d[i] i -= i & -i return res def sum(self, l, r): return self._sum(r) - self._sum(l) import sys input=sys.stdin.readline n=int(input()) T,X,Y=map(list,zip(*[map(int,input().split()) for _ in range(n)])) zaatu=[] for t,x,y in zip(T,X,Y): zaatu.append(x) if t==1: zaatu.append(y) zaatu.append(y+1) zaatu={x:i for i,x in enumerate(sorted(set(zaatu)))} bit=DynamicBIT(len(zaatu)) ans=0 for t,*query in zip(T,X,Y): if t==0: x,y=query bit.add(zaatu[x],y) else: l,r=query ans+=bit.sum(zaatu[l],zaatu[r]+1) print(ans)