結果
問題 | No.789 範囲の合計 |
ユーザー |
👑 |
提出日時 | 2022-09-30 23:00:10 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,286 bytes |
コンパイル時間 | 86 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 50,232 KB |
最終ジャッジ日時 | 2024-12-23 00:43:45 |
合計ジャッジ時間 | 9,941 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 TLE * 1 |
ソースコード
class Bit: def __init__(self, n): self.size = n self.n0 = 1 << (n.bit_length() - 1) self.tree = [0] * (n + 1) def range_sum(self, l, r): return self.sum(r - 1) - self.sum(l - 1) def sum(self, i): i += 1 s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def get(self, i): return self.sum(i) - self.sum(i - 1) def add(self, i, x): i += 1 while i <= self.size: self.tree[i] += x i += i & -i def lower_bound(self, x): pos = 0 plus = self.n0 while plus > 0: if pos + plus <= self.size and self.tree[pos + plus] < x: x -= self.tree[pos + plus] pos += plus plus //= 2 return pos n = int(input()) query = [] X = set() for _ in range(n): t, x, y = map(int, input().split()) X.add(x) if t == 1: y += 1 X.add(y) query.append((t, x, y)) n = len(X) lst = sorted(X) dic = {l:i for i, l in enumerate(lst)} bit = Bit(n) ans = 0 for t, x, y in query: x = dic[x] if t == 0: bit.add(x, y) else: y = dic[y] ans += bit.range_sum(x, y) print(ans)