結果
問題 | No.2220 Range Insert & Point Mex |
ユーザー | LyricalMaestro |
提出日時 | 2024-01-24 02:39:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 846 ms / 2,000 ms |
コード長 | 3,436 bytes |
コンパイル時間 | 333 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 264,144 KB |
最終ジャッジ日時 | 2024-09-28 06:57:32 |
合計ジャッジ時間 | 16,569 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,480 KB |
testcase_01 | AC | 37 ms
52,416 KB |
testcase_02 | AC | 38 ms
52,608 KB |
testcase_03 | AC | 41 ms
52,608 KB |
testcase_04 | AC | 39 ms
52,480 KB |
testcase_05 | AC | 41 ms
53,632 KB |
testcase_06 | AC | 40 ms
52,992 KB |
testcase_07 | AC | 39 ms
52,608 KB |
testcase_08 | AC | 39 ms
52,480 KB |
testcase_09 | AC | 40 ms
52,608 KB |
testcase_10 | AC | 39 ms
53,100 KB |
testcase_11 | AC | 38 ms
52,608 KB |
testcase_12 | AC | 40 ms
52,864 KB |
testcase_13 | AC | 628 ms
187,428 KB |
testcase_14 | AC | 629 ms
187,496 KB |
testcase_15 | AC | 628 ms
187,760 KB |
testcase_16 | AC | 623 ms
187,620 KB |
testcase_17 | AC | 624 ms
187,628 KB |
testcase_18 | AC | 612 ms
187,720 KB |
testcase_19 | AC | 623 ms
187,724 KB |
testcase_20 | AC | 824 ms
263,536 KB |
testcase_21 | AC | 846 ms
264,144 KB |
testcase_22 | AC | 844 ms
263,888 KB |
testcase_23 | AC | 444 ms
176,916 KB |
testcase_24 | AC | 359 ms
155,904 KB |
testcase_25 | AC | 326 ms
156,580 KB |
testcase_26 | AC | 350 ms
152,560 KB |
testcase_27 | AC | 238 ms
135,012 KB |
testcase_28 | AC | 168 ms
136,680 KB |
testcase_29 | AC | 163 ms
123,264 KB |
testcase_30 | AC | 165 ms
123,136 KB |
testcase_31 | AC | 285 ms
136,212 KB |
testcase_32 | AC | 311 ms
141,192 KB |
testcase_33 | AC | 306 ms
141,192 KB |
testcase_34 | AC | 562 ms
162,692 KB |
testcase_35 | AC | 593 ms
162,948 KB |
testcase_36 | AC | 452 ms
147,352 KB |
testcase_37 | AC | 495 ms
147,616 KB |
testcase_38 | AC | 457 ms
182,380 KB |
ソースコード
## https://yukicoder.me/problems/no/2220 class BinaryIndexTree: """ フェニック木(BinaryIndexTree)の基本的な機能を実装したクラス """ def __init__(self, size): self.size = size self.array = [0] * (size + 1) def add(self, x, a): index = x while index <= self.size: self.array[index] += a index += index & (-index) def sum(self, x): index = x ans = 0 while index > 0: ans += self.array[index] index -= index & (-index) return ans def least_upper_bound(self, value): if self.sum(self.size) < value: return -1 elif value <= 0: return 0 m = 1 while m < self.size: m *= 2 k = 0 k_sum = 0 while m > 0: k0 = k + m if k0 < self.size: if k_sum + self.array[k0] < value: k_sum += self.array[k0] k += m m //= 2 if k < self.size: return k + 1 else: return -1 def main(): N = int(input()) add_ops = [] for _ in range(N): l, r, a = map(int, input().split()) add_ops.append((l, r, a)) Q = int(input()) X = list(map(int, input().split())) # 集合indexに関する座標圧縮 index_set = set() for l, r, _ in add_ops: index_set.add(l) index_set.add(r) for x in X: index_set.add(x) index_list = sorted(list(index_set)) index_map = {} for i, index in enumerate(index_list): index_map[index] = i # Mex計算用の値に関する座標圧縮 value_set = set() value_set.add(0) value_set.add(1) for _, _, a in add_ops: value_set.add(a) value_set.add(a + 1) value_list = sorted(list(value_set)) value_map = {} for i, value in enumerate(value_list): value_map[value] = i + 1 # イベント登録 add_events = {} remove_events = {} calc_events = {} for l, r, a in add_ops: l = index_map[l] r = index_map[r] a = value_map[a] if l not in add_events: add_events[l] = [] add_events[l].append(a) if r not in remove_events: remove_events[r] = [] remove_events[r].append(a) for x in X: calc_events[index_map[x]] = 1 # イベントをindexの若い順に実行 value_max = len(value_list) bit = BinaryIndexTree(value_max) for i in range(1, value_max + 1): bit.add(i, 1) added_value_map = [0] * (value_max + 1) answer = [] for i in range(len(index_list)): if i in add_events: for a in add_events[i]: added_value_map[a] += 1 if added_value_map[a] == 1: bit.add(a, -1) if i in calc_events: a = bit.least_upper_bound(1) if a == 0: answer.append(0) else: answer.append(value_list[a - 1]) if i in remove_events: for a in remove_events[i]: added_value_map[a] -= 1 if added_value_map[a] == 0: bit.add(a, 1) for ans in answer: print(ans) if __name__ == "__main__": main()