/* ---------------- Competitive Programming Template for ICPC and Other Competitions ---------------- */ #include #define _USE_MATH_DEFINES #include #include #include #include using namespace std; /* ------------------- FAST I/O ------------------- */ #define fast_io ios::sync_with_stdio(false);cin.tie(nullptr) /* ------------------- TYPE ALIASES ------------------- */ using ll = long long; using lld = long double; using vll = vector; using vlld = vector; using vb = vector; using vvll = vector>; using vvlld = vector>; using pll = pair; using plld = pair; /* ------------------- MACROS ------------------- */ #define rep(i,a,b) for(ll i=(a);i<(b);++i) #define per(i,a,b) for(ll i=(a);i>=(b);--i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb push_back #define eb emplace_back #define fi first #define se second #define sz(x) ((ll)(x).size()) #define nl "\n" /* ------------------- CONSTANTS ------------------- */ const ll MOD = 1e9 + 7; const ll INF = LLONG_MAX; /* --------------- GCD and LCM --------------- */ inline ll gcd(ll a,ll b){ return b ? gcd(b,a%b) : a; } inline ll lcm(ll a,ll b){ return (a/gcd(a,b))*b; } /* --------------- FASTER INPUT/OUTPUT --------------- */ namespace __input { template void re(T &x){ cin >> x; } void re(lld &x){ string t; cin >> t; x=stold(t); } template void re(pair &p){ re(p.first,p.second); } template void re(vector &a){ for(auto &x:a) re(x); } template void re(array &a){ for(auto &x:a) re(x); } template void re(Arg &f,Args &...r){ re(f); re(r...); } } using namespace __input; namespace __output { template void pr(const T &x){ cout< void pr(const pair &p){ pr(p.first);pr(" ");pr(p.second); } template void pr(const Arg &f,const Args &...r){ pr(f);pr(" ");pr(r...); } template void pr(const vector &x){ for(const auto &a:x){ pr(a); pr(" "); } } void ps(){ pr("\n"); } template void ps(const Arg &f){ pr(f); ps(); } template void ps(const Arg &f,const Args &...r){ pr(f); pr(" "); ps(r...); } } using namespace __output; /* --------------- CONDITIONAL DEBUG PRIMITIVES --------------- */ #if defined(LOCAL) && LOCAL == SALMAN // SALMAN build: enable debug printing #define debug_pr(...) pr(__VA_ARGS__) // print without newline #define debug_ps(...) ps(__VA_ARGS__) // print with newline #else // non-SALMAN build: disable debug printing #define debug_pr(...) /* no-op */ #define debug_ps(...) /* no-op */ #endif /* --------------- RANDOM HELPER --------------- */ mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); inline ll random_in_range(ll l,ll r){ uniform_int_distribution dist(l,r); return dist(rng); } /* --------------- SOLVE --------------- */ void solve(){ ll N; re(N); vll a(N); map mp; rep(i, 0, N) { ll c, d; re(c, d); a[i] = c; mp[d].eb(c); } for (auto &[c, d]: mp) { sort(all(d)); } sort(all(a)); ll Q; re(Q); rep(i, 0, Q) { ll c, d; re(c, d); ll res = distance(a.begin(), upper_bound(all(a), c)) - distance(mp[d].begin(), upper_bound(all(mp[d]), c)); // ps(distance(a.begin(), upper_bound(all(a), c)), distance(mp[d].begin(), lower_bound(all(mp[d]), c))); ps(res); } } /* --------------- MAIN --------------- */ int main(){ fast_io; #if defined(LOCAL) && LOCAL == SALMAN // Record start time auto start = std::chrono::high_resolution_clock::now(); #endif // // Precomputations Needed for Your Code // precompute_factorials(); // ? Required for nCr(n, r) // sieve(MAXN); // ? Required for prime-related functions // compute_totient(); // ? Required for ?(n) calculations // compute_mobius(); // ? Required for Möbius function calculations cout << setprecision(12) << fixed; ll T=1; // cin >> T; while(T--) solve(); #if defined(LOCAL) && LOCAL == SALMAN // Record end time auto end = std::chrono::high_resolution_clock::now(); // Calculate duration std::chrono::duration duration = end - start; // Output duration in seconds std::cout << "Execution time: " << duration.count() << " seconds" << std::endl; #endif return 0; }