/* -*- coding: utf-8 -*- * * 3085.cc: No.3085 Easy Problems - yukicoder */ #include #include #include using namespace std; /* constant */ const int MAX_N = 200000; const int MAX_B = 100000; /* typedef */ using vi = vector; /* global variables */ int as[MAX_N], bs[MAX_N]; vi bvs[MAX_B]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d", as + i, bs + i), bs[i]--; for (int i = 0; i < n; i++) bvs[bs[i]].push_back(as[i]); for (int b = 0; b < MAX_B; b++) if (! bvs[b].empty()) sort(bvs[b].begin(), bvs[b].end()); sort(as, as + n); int qn; scanf("%d", &qn); while (qn--) { int x, y; scanf("%d%d", &x, &y), y--; auto &bv = bvs[y]; int ca = upper_bound(as, as + n, x) - as; int cb = upper_bound(bv.begin(), bv.end(), x) - bv.begin(); printf("%d\n", ca - cb); } return 0; }