# https://qiita.com/ether2420/items/7b67b2b35ad5f441d686 def segfunc(x,y): return x+y class LazySegTree_RUQ: def __init__(self,init_val,segfunc,ide_ele): n = len(init_val) self.segfunc = segfunc self.ide_ele = ide_ele self.num = 1<<(n-1).bit_length() self.tree = [ide_ele]*2*self.num self.lazy = [None]*2*self.num for i in range(n): self.tree[self.num+i] = init_val[i] for i in range(self.num-1,0,-1): self.tree[i] = self.segfunc(self.tree[2*i],self.tree[2*i+1]) def gindex(self,l,r): l += self.num r += self.num lm = l>>(l&-l).bit_length() rm = r>>(r&-r).bit_length() while r>l: if l<=lm: yield l if r<=rm: yield r r >>= 1 l >>= 1 while l: yield l l >>= 1 def propagates(self,*ids): for i in reversed(ids): v = self.lazy[i] if v is None: continue self.lazy[i] = None self.lazy[2*i] = v self.lazy[2*i+1] = v self.tree[2*i] = v self.tree[2*i+1] = v def update(self,l,r,x): ids = self.gindex(l,r) self.propagates(*self.gindex(l,r)) l += self.num r += self.num while l>= 1 l >>= 1 for i in ids: self.tree[i] = self.segfunc(self.tree[2*i], self.tree[2*i+1]) def query(self,l,r): ids = self.gindex(l,r) self.propagates(*self.gindex(l,r)) res = self.ide_ele l += self.num r += self.num while l>= 1 r >>= 1 return res import bisect import sys input = sys.stdin.readline N, A = map(int, input().split()) X = list(map(int, input().split())) T = int(input()) LR = [list(map(int, input().split())) for _ in range(T)] for i in range(N): x = X[i] X[i] = (x, i) X.sort() ST = LazySegTree_RUQ([0 for _ in range(N)], segfunc, 0) for t in range(T): l, r = LR[t] l_pos = bisect.bisect_left(X, (l, 0)) r_pos = bisect.bisect_left(X, (r, N)) ST.update(l_pos, r_pos, t+1) ans = [-1 for _ in range(N)] for i in range(N): tmp = ST.query(i, i+1) x, idx = X[i] if tmp==0: ans[idx] = -1 else: ans[idx] = tmp for a in ans: print(a)