## https://yukicoder.me/problems/no/1982 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, K, Q = map(int, input().split()) lrch = [] for _ in range(K): l, r, c, h = map(int, input().split()) lrch.append((l - 1, r - 1, c, h)) ix = [] for _ in range(Q): i, x = map(int, input().split()) ix.append((i - 1, x)) # イベントの管理 events = [[] for _ in range(N)] color_map = [0] * K for i, (l, r, c, h) in enumerate(lrch): events[l].append((0, i, c, h)) events[r].append((2, i, c, h)) color_map[i] = c for i, (I, x) in enumerate(ix): events[I].append((1, i, x, 0)) for i in range(N): events[i].sort() height_bit = BinaryIndexTree(K) answers = [-1] * Q for i in range(N): for event in events[i]: if event[0] == 0: _, i, _, h = event height_bit.add(i + 1, h) elif event[0] == 1: _, i, x, _ = event ans = height_bit.least_upper_bound(x) if ans >= 0: c = color_map[ans - 1] answers[i] = c elif event[0] == 2: _, i, _, h = event height_bit.add(i + 1, -h) for ans in answers: print(ans) if __name__ == '__main__': main()