結果
問題 | No.649 ここでちょっとQK! |
ユーザー | Kohno |
提出日時 | 2022-07-24 22:24:00 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,560 bytes |
コンパイル時間 | 202 ms |
コンパイル使用メモリ | 82,588 KB |
実行使用メモリ | 181,716 KB |
最終ジャッジ日時 | 2024-07-06 17:41:51 |
合計ジャッジ時間 | 12,084 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 36 ms
54,232 KB |
testcase_02 | WA | - |
testcase_03 | AC | 210 ms
97,288 KB |
testcase_04 | AC | 399 ms
156,536 KB |
testcase_05 | AC | 408 ms
156,960 KB |
testcase_06 | AC | 318 ms
115,020 KB |
testcase_07 | AC | 35 ms
54,056 KB |
testcase_08 | AC | 36 ms
54,380 KB |
testcase_09 | WA | - |
testcase_10 | AC | 36 ms
55,528 KB |
testcase_11 | AC | 35 ms
54,448 KB |
testcase_12 | AC | 302 ms
123,468 KB |
testcase_13 | AC | 295 ms
123,616 KB |
testcase_14 | AC | 306 ms
123,640 KB |
testcase_15 | AC | 322 ms
123,488 KB |
testcase_16 | AC | 305 ms
123,104 KB |
testcase_17 | AC | 337 ms
128,608 KB |
testcase_18 | AC | 351 ms
134,732 KB |
testcase_19 | AC | 378 ms
141,672 KB |
testcase_20 | AC | 410 ms
129,120 KB |
testcase_21 | AC | 440 ms
153,736 KB |
testcase_22 | AC | 456 ms
154,940 KB |
testcase_23 | AC | 471 ms
164,904 KB |
testcase_24 | AC | 503 ms
165,668 KB |
testcase_25 | AC | 530 ms
175,780 KB |
testcase_26 | AC | 563 ms
181,716 KB |
testcase_27 | WA | - |
testcase_28 | AC | 65 ms
72,236 KB |
testcase_29 | AC | 62 ms
70,432 KB |
testcase_30 | AC | 281 ms
112,748 KB |
testcase_31 | AC | 283 ms
112,140 KB |
testcase_32 | AC | 37 ms
54,648 KB |
testcase_33 | AC | 37 ms
53,684 KB |
testcase_34 | AC | 37 ms
54,616 KB |
testcase_35 | AC | 37 ms
54,168 KB |
ソースコード
class SegmentTree(object): def __init__(self, v, op, e): self._n = len(v) self.op = op self.e = e self.log = SegmentTree._ceil_pow2(self._n) self.size = 1 << self.log self.d = [self.e] * 2 * self.size for i in range(self._n): self.d[self.size + i] = v[i] for i in range(self.size - 1, 0, -1): self._update(i) @staticmethod def _ceil_pow2(n): for x in range(64): if 1 << x >= n: break return x def _update(self, k): self.d[k] = self.op(self.d[2 * k], self.d[2 * k + 1]) def __getitem__(self, p): assert 0 <= p < self._n return self.d[p + self.size] def __setitem__(self, p, x): assert 0 <= p < self._n p += self.size self.d[p] = x for i in range(1, self.log + 1): self._update(p >> i) def __str__(self): return str(self.d[self.size:]) def query(self, l, r): if l is ...: l = 0 if r is ...: r = self._n assert 0 <= l <= r <= self._n sml = self.e smr = self.e l += self.size r += self.size while l < r: if l & 1: sml = self.op(sml, self.d[l]) l += 1 if r & 1: r -= 1 smr = self.op(self.d[r], smr) l >>= 1 r >>= 1 return self.op(sml, smr) def max_right(self, l, f): if l is ...: l = 0 assert 0 <= l <= self._n assert f(self.e) if l == self._n: return self._n l += self.size sm = self.e while True: while l & 1 == 0: l >>= 1 if not f(self.op(sm, self.d[l])): while l < self.size: l <<= 1 if f(self.op(sm, self.d[l])): sm = self.op(sm, self.d[l]) l += 1 return l - self.size sm = self.op(sm, self.d[l]) l += 1 if (l & -l) == l: break return self._n def min_left(self, r, f): if r is ...: r = self._n assert 0 <= r <= self._n assert f(self.e) if r == 0: return 0 r += self.size sm = self.e while True: r -= 1 while r > 1 and r & 1: r >>= 1 if not f(self.op(self.d[r], sm)): while r < self.size: r <<= 1 r += 1 if f(self.op(self.d[r], sm)): sm = self.op(self.d[r], sm) r -= 1 return r + 1 - self.size sm = self.op(self.d[r], sm) if (r & -r) == r: break return 0 class _CountOrItem(object): def __init__(self, _tree_map): self._tree = _tree_map._tree self._g = _tree_map._g def _bind(self, l, r): self._l = l self._r = r def _predicate(self, s): return s < self._tree.query(self._l, self._r) def count(self): return self._tree.query(self._l, self._r) def item(self): try: if self._l is ...: i = self._tree.max_right(..., self._predicate) else: i = self._tree.min_left(..., self._predicate) - 1 except AssertionError: return None return self._g[i] if 0 <= i < len(self._g) else None from operator import add class LimitedTreeMap(object): def __init__(self, domain): self._g = sorted(set(domain)) self._f = {v: k for k, v in enumerate(self._g)} self._tree = SegmentTree([0] * len(self._g), add, 0) self._count_or_item = _CountOrItem(self) def __setitem__(self, p, x): p = self._f[p] self._tree[p] = x def __getitem__(self, p): p = self._f[p] return self._tree[p] def __str__(self): return str({v: self._tree[k] for v, k in self._f.items() if self._tree[k]}) def __repr__(self): return str({v: self._tree[k] for v, k in self._f.items() if self._tree[k]}) def __lt__(self, p): p = self._f[p] self._count_or_item._bind(..., p) return self._count_or_item def __le__(self, p): p = self._f[p] self._count_or_item._bind(..., p + 1) return self._count_or_item def __gt__(self, p): p = self._f[p] self._count_or_item._bind(p + 1, ...) return self._count_or_item def __ge__(self, p): p = self._f[p] self._count_or_item._bind(p, ...) return self._count_or_item def k_smallest(self, k): i = self._tree.max_right(..., lambda s: s < k + 1) return self._g[i] if 0 <= i < len(self._g) else None def k_largest(self, k): i = self._tree.min_left(..., lambda s: s < k + 1) - 1 return self._g[i] if 0 <= i < len(self._g) else None q, k = map(int, input().split()) domain = [] queries = [] for _ in range(q): t, *args = map(int, input().split()) if t == 1: domain.append(*args) queries.append((t, *args)) tree_map = LimitedTreeMap(domain) for t, *args in queries: if t == 1: x, = args tree_map[x] += 1 else: x = tree_map.k_smallest(k - 1) or -1 if x >= 0: tree_map[x] -= 1 print(x)