結果
問題 | No.877 Range ReLU Query |
ユーザー | 👑 rin204 |
提出日時 | 2022-07-06 07:26:39 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 683 ms / 2,000 ms |
コード長 | 1,631 bytes |
コンパイル時間 | 254 ms |
コンパイル使用メモリ | 82,148 KB |
実行使用メモリ | 152,140 KB |
最終ジャッジ日時 | 2024-04-25 22:37:34 |
合計ジャッジ時間 | 8,406 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
53,408 KB |
testcase_01 | AC | 54 ms
70,068 KB |
testcase_02 | AC | 55 ms
69,872 KB |
testcase_03 | AC | 65 ms
75,688 KB |
testcase_04 | AC | 41 ms
60,228 KB |
testcase_05 | AC | 49 ms
64,112 KB |
testcase_06 | AC | 49 ms
66,060 KB |
testcase_07 | AC | 48 ms
64,016 KB |
testcase_08 | AC | 63 ms
73,252 KB |
testcase_09 | AC | 42 ms
60,328 KB |
testcase_10 | AC | 56 ms
69,388 KB |
testcase_11 | AC | 643 ms
143,640 KB |
testcase_12 | AC | 552 ms
133,068 KB |
testcase_13 | AC | 494 ms
128,452 KB |
testcase_14 | AC | 507 ms
131,436 KB |
testcase_15 | AC | 675 ms
152,140 KB |
testcase_16 | AC | 645 ms
147,024 KB |
testcase_17 | AC | 675 ms
150,368 KB |
testcase_18 | AC | 683 ms
147,148 KB |
testcase_19 | AC | 565 ms
137,380 KB |
testcase_20 | AC | 599 ms
148,908 KB |
ソースコード
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, Q = map(int, input().split()) A = list(map(int, input().split())) se = set(A) L = [[] for _ in range(n)] R = [[] for _ in range(n)] X = [0] * Q for i in range(Q): _, l, r, X[i] = map(int, input().split()) L[l - 1].append(i) R[r - 1].append(i) se.add(X[i]) lst = sorted(se) dic = {l:i for i, l in enumerate(lst)} le = len(lst) + 1 tot = Bit(le) cnt = Bit(le) ans = [0] * Q for i, a in enumerate(A): for j in L[i]: x = dic[X[j]] tmp = tot.range_sum(x + 1, le) - cnt.range_sum(x + 1, le) * X[j] ans[j] -= tmp cnt.add(dic[a], 1) tot.add(dic[a], a) for j in R[i]: x = dic[X[j]] tmp = tot.range_sum(x + 1, le) - cnt.range_sum(x + 1, le) * X[j] ans[j] += tmp print(*ans, sep="\n")