## 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()