#include using namespace std; typedef long long LL; struct I{ I(){ ios::sync_with_stdio(false);cin.tie(0); } }cww; namespace BIT_{ #define CNT 4 #define SZ 700000 int cnt=0; LL mem[CNT][SZ]; } class BIT{ private: LL *t;int n; public: BIT(int n):t(BIT_::mem[BIT_::cnt++]),n(n){ fill(t,t+n,0); } LL sum(int i){ LL s=0; while(i>0){ s+=t[i]; i-=i&-i; } return s; } LL sum(int lb,int ub){ return sum(ub)-sum(lb-1); } void add(int i,LL x){ while(i<=n){ t[i]+=x,i+=i&-i; } } }; int main(){ int N,Q;cin>>N; map z; vector a(N); for(auto &it:a){ cin>>it; z[it]=0; } cin>>Q; vector L(Q),H(Q); for(int i=0;i>L[i]>>H[i]; z[L[i]]=z[H[i]]=0; } int Z=1; int LB=0; int UB=1e9+1; z[LB]=z[UB]=1; for(auto &it:z)it.second=Z++; LB=z[LB]; UB=z[UB]; for(auto &it:a)it=z[it]; for(auto &it:L)it=z[it]; for(auto &it:H)it=z[it]; BIT res(Z),l(Z),r(Z),same(Z); for(auto &it:a)r.add(it,1); for(int i=0;i