//Maqsad Nahi Bhoolna #include #include #include using namespace std; using namespace __gnu_pbds; template using min_heap = priority_queue, greater>; template using max_heap = priority_queue; template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; //find_by_order(k): returns iterator to k-th smallest element (0-based) //order_of_key(x): returns number of elements strictly less than x #define ll long long int #define ld long double #define nl cout<<"\n" #define re return 0 #define fs first #define sc second #define MOD 1000000007 #define pii pair #define vl vector #define vll vector> #define vpii vector> #define vvpii vector>> #define vb vector #define vbb vector> #define us unordered_set #define all(vec) vec.begin(), vec.end() #define allr(vec) vec.rbegin(), vec.rend() #define sahi(vec) sort(vec.begin(),vec.end()) #define ulta(vec) sort(vec.begin(),vec.end(),greater()) #define fori(a,b) for(ll i=a;i=b;r--) #define yes(expr) (expr)? cout<<"yes" : cout<<"no" #define Yes(expr) (expr)? cout<<"Yes" : cout<<"No" #define YES(expr) (expr)? cout<<"YES" : cout<<"NO" #define print(vec) for(auto x : vec) cout< istream& operator>>(istream &in, pair &p) { in >> p.first >> p.second; return in; } template istream& operator>>(istream &in, vector &v) { for (auto &x : v) in >> x; return in; } template istream& operator>>(istream &in, vector> &vp) { for (auto &p : vp) in >> p.first >> p.second; return in; } template ostream& operator<<(ostream &out, const pair &p) { out << p.first << " " << p.second; return out; } template ostream& operator<<(ostream &out, const vector &v) { for (auto &x : v) out << x << " "; return out; } template ostream& operator<<(ostream &out, const vector> &vp) { for (auto &p : vp) out << p.first << " " << p.second << "\n"; return out; } vb is_prime; void sieve(ll n) { is_prime.assign(n+1,true); is_prime[0] = is_prime[1] = false; for(ll i=2;i*i<=n;i++) { if(is_prime[i]) { for(ll j=i*i;j<=n;j+=i) is_prime[j] = false; } } } bool isprime(ll n) { if(n<2) return false; if(n==2 || n==3) return true; if(n%2==0 || n%3==0) return false; for(ll i=5;i*i<=n;i+=6) { if(n%i==0 || n%(i+2)==0) return false; } return true; } ll nextprime(ll n) { return (isprime(n))? n : nextprime(n+1); } ll sum_digits(ll n) { return (n<10)? n : n%10 + sum_digits(n/10); } ll gcd(ll a, ll b) { return (b==0)? a : gcd(b,a%b); } ll lcm(ll a, ll b) { return (a*b)/gcd(a,b); } int main() { io; ll n; cin>>n; vpii arr(n); cin>>arr; ll x; cin>>x; vpii uss(x); cin>>uss; sahi(arr); vl bin(n); fori(0,n) bin[i] = arr[i].fs; vpii count(n); fori(0,n) { count[i].fs = arr[i].sc; count[i].sc = arr[i].fs; } sahi(count); vl type(n); fori(0,n) type[i] = count[i].fs; vl value(n); fori(0,n) value[i] = count[i].sc; function f = [&](ll cur, ll z) { auto it1 = lower_bound(all(type),z); auto it2 = upper_bound(all(type),z); ll d1 = it1-type.begin(); ll d2 = it2-type.begin(); auto it3 = upper_bound(value.begin()+d1,value.begin()+d2,cur); ll now = it3-(value.begin()+d1); return now; }; fori(0,x) { auto it = upper_bound(all(bin),uss[i].fs); ll d = it-bin.begin(); ll z = uss[i].sc; cout<