# T=int(input()) # for i in range(T): N,A=map(int,input().split()) #N=int(input()) X=list(map(int, input().split())) C=[] for i in range(N): C.append((X[i],i)) C=sorted(C) D=sorted(X) #print(C,D) import bisect import sys class Lazysegtree: def __init__(self, A, intv, initialize = True): #区間は 1-indexed で管理 self.N = len(A) self.N0 = 2**(self.N-1).bit_length() self.intv = intv #self.segf = segf self.lazy = [None]*(2*self.N0) if initialize: self.data = [intv]*self.N0 + A + [intv]*(self.N0 - self.N) for i in range(self.N0-2, -1, -1): self.data[i] = min(self.data[2*i], self.data[2*i+1]) else: self.data = [intv]*(2*self.N0) def _ascend(self, k): k = k >> 1 c = k.bit_length() for j in range(c): idx = k >> j self.data[idx] = min(self.data[2*idx], self.data[2*idx+1]) def _descend(self, k): k = k >> 1 idx = 1 c = k.bit_length() for j in range(1, c+1): idx = k >> (c - j) if self.lazy[idx] is None: continue self.data[2*idx] = self.data[2*idx+1] = self.lazy[2*idx] \ = self.lazy[2*idx+1] = self.lazy[idx] self.lazy[idx] = None def query(self, l, r): L = l+self.N0 R = r+self.N0 self._descend(L//(L & -L)) self._descend(R//(R & -R) - 1) s = self.intv while L < R: if R & 1: R -= 1 s = min(s, self.data[R]) if L & 1: s = min(s, self.data[L]) L += 1 L >>= 1 R >>= 1 return s def update(self, l, r, x): L = l+self.N0 R = r+self.N0 Li = L//(L & -L) Ri = R//(R & -R) self._descend(Li) self._descend(Ri-1) while L < R : if R & 1: R -= 1 self.data[R] = x self.lazy[R] = x if L & 1: self.data[L] = x self.lazy[L] = x L += 1 L >>= 1 R >>= 1 self._ascend(Li) self._ascend(Ri-1) T = Lazysegtree([0]*(N+10), 2**31-1, initialize = False) Q=int(input()) for i in range(Q): l,r=map(int,input().split()) ll,rr=bisect.bisect_left(D,l),bisect.bisect_right(D,r) T.update(ll,rr,i+2) E=[] for i in range(N): E.append(T.query(i,i+1)) ans=[-1]*N;now=0 for _,x in C: e=E[now] now+=1 if e!=2147483647: ans[x]=e-1 for i in ans: print(i)