結果
問題 | No.789 範囲の合計 |
ユーザー | mkawa2 |
提出日時 | 2021-02-12 09:00:24 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 809 ms / 1,000 ms |
コード長 | 1,072 bytes |
コンパイル時間 | 400 ms |
コンパイル使用メモリ | 10,840 KB |
実行使用メモリ | 53,828 KB |
最終ジャッジ日時 | 2023-09-26 07:44:26 |
合計ジャッジ時間 | 8,585 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 20 ms
9,808 KB |
testcase_01 | AC | 20 ms
9,676 KB |
testcase_02 | AC | 752 ms
46,960 KB |
testcase_03 | AC | 403 ms
24,464 KB |
testcase_04 | AC | 698 ms
46,528 KB |
testcase_05 | AC | 642 ms
46,364 KB |
testcase_06 | AC | 684 ms
46,580 KB |
testcase_07 | AC | 409 ms
24,728 KB |
testcase_08 | AC | 526 ms
36,628 KB |
testcase_09 | AC | 495 ms
36,788 KB |
testcase_10 | AC | 809 ms
53,828 KB |
testcase_11 | AC | 633 ms
46,336 KB |
testcase_12 | AC | 633 ms
46,328 KB |
testcase_13 | AC | 21 ms
9,660 KB |
testcase_14 | AC | 20 ms
9,900 KB |
ソースコード
import sys def II(): return int(sys.stdin.buffer.readline()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] 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)