from atcoder.lazysegtree import LazySegTree class Compression: def __init__(self, iterable): self.xs = sorted(set(iterable)) self.n = len(self.xs) self.x2i = {} for i, x in enumerate(self.xs): self.x2i[x] = i def __len__(self): return self.n def index(self, x): """x のインデックスを返す""" return self.x2i[x] def value(self, index): """インデックスに対応する値を返す""" return self.xs[index] # 値データ S = int # 遅延データ F = int # 値データを合成 def op(a: S, b: S) -> S: # 使わない return 0 # 遅延データを値データに反映 : f(x) def mapping(f: F, x: S) -> S: if f == 0: return x return f # 遅延データを伝搬 # 二つの遅延データを合成 : (f . g) def composition(f: F, g: F) -> F: if f == 0: return g return f N, A = map(int, input().split()) X = list(map(int, input().split())) ss = set(X) T = int(input()) segs = [] for _ in range(T): L, R = map(int, input().split()) segs.append((L, R)) ss.add(L) ss.add(R) comp = Compression(ss) # 単位元 e : 全ての a に対して op(a, e) = op(e, a) = a を満たす # 恒等写像 id : 全ての a に対して mapping(id, a) = a を満たす lsegt = LazySegTree( op=op, e=0, mapping=mapping, composition=composition, id_=0, v=[-1] * len(comp)) for i, (l, r) in enumerate(segs): li = comp.index(l) ri = comp.index(r) lsegt.apply(li, ri+1, i+1) ans = [lsegt.get(comp.index(x)) for x in X] print(*ans, sep='\n')