class SegmentTree: def __init__(self, size): self.size = 2**(size - 1).bit_length() self.data = [-1]*(2*self.size) def update(self, k, x): k += self.size self.data[k] = x while k > 0: k >>= 1 self.data[k] = max(self.data[k*2], self.data[k*2+1]) def query(self, l, r): L = l + self.size R = r + self.size s = -1 while L < R: if R & 1: R -= 1 s = max(s, self.data[R]) if L & 1: s = max(s, self.data[L]) L += 1 L >>= 1 R >>= 1 return s import bisect N, A = map(int, input().split()) X = sorted(list(map(int, input().split()))) T = int(input()) LR = [list(map(int, input().split())) for _ in range(T)] seg_tree = SegmentTree(N) for t in range(T): L, R = LR[t] start = bisect.bisect_left(X, L) end = bisect.bisect_right(X, R) for i in range(start, end): seg_tree.update(i, t+1) for i in range(N): print(seg_tree.query(i, i+1))