結果
問題 | No.2065 Sum of Min |
ユーザー | 👑 rin204 |
提出日時 | 2022-09-02 21:31:01 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 901 ms / 2,000 ms |
コード長 | 1,425 bytes |
コンパイル時間 | 259 ms |
コンパイル使用メモリ | 82,488 KB |
実行使用メモリ | 104,548 KB |
最終ジャッジ日時 | 2024-04-27 20:58:16 |
合計ジャッジ時間 | 14,984 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
52,880 KB |
testcase_01 | AC | 32 ms
52,836 KB |
testcase_02 | AC | 33 ms
52,424 KB |
testcase_03 | AC | 33 ms
52,868 KB |
testcase_04 | AC | 443 ms
103,260 KB |
testcase_05 | AC | 449 ms
101,704 KB |
testcase_06 | AC | 565 ms
103,264 KB |
testcase_07 | AC | 225 ms
98,900 KB |
testcase_08 | AC | 565 ms
104,024 KB |
testcase_09 | AC | 727 ms
103,904 KB |
testcase_10 | AC | 696 ms
103,752 KB |
testcase_11 | AC | 704 ms
103,384 KB |
testcase_12 | AC | 739 ms
103,884 KB |
testcase_13 | AC | 748 ms
104,192 KB |
testcase_14 | AC | 901 ms
103,508 KB |
testcase_15 | AC | 739 ms
103,892 KB |
testcase_16 | AC | 741 ms
104,548 KB |
testcase_17 | AC | 733 ms
103,640 KB |
testcase_18 | AC | 736 ms
104,000 KB |
testcase_19 | AC | 725 ms
103,640 KB |
testcase_20 | AC | 734 ms
104,016 KB |
testcase_21 | AC | 736 ms
104,128 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())) B = [(a, i) for i, a in enumerate(A)] B.sort() query = [] for i in range(Q): l, r, x = map(int, input().split()) l -= 1 query.append((x, l, r, i)) query.sort() ans = 0 cnt = Bit(n) tot = Bit(n) B.append((1 << 50, -1)) t = 0 ans = [0] * Q for x, l, r, i in query: while B[t][0] < x: tot.add(B[t][1], B[t][0]) cnt.add(B[t][1], 1) t += 1 cn = cnt.range_sum(l, r) to = tot.range_sum(l, r) ans[i] = to + (r - l - cn) * x print(*ans, sep="\n")