#include #include #include #include #include #include #include #include using namespace std; void coco(vector& v) { size_t n = v.size(); vector> t(n); for (int i = 0; i < n; i++) { t[i] = { v[i], i }; } sort(t.begin(), t.end()); int k = 0; for (int i = 0; i < n; i++) { if (i > 0 && t[i].first != t[i - 1].first) k++; v[t[i].second] = k; } } struct BIT { BIT(int n) : b(n + 1), n(n) {} void add(int i, int v) { for (int k = i + 1; k <= n; k += k & -k) b[k] += v; } int sum(int k) { int s = 0; for (; k > 0; k -= k & -k) s += b[k]; return s; } vector b; int n; }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } int m; cin >> m; a.resize(n + m); b.resize(n + m); for (int i = 0; i < m; i++) { cin >> a[n + i] >> b[n + i]; } coco(a); coco(b); vector> p(n); vector, int>> q(m); for (int i = 0; i < n; i++) { p[i] = { a[i], b[i] }; } for (int j = 0; j < m; j++) { q[j].first = { a[n + j], b[n + j] }; q[j].second = j; } sort(p.begin(), p.end(), greater<>()); sort(q.begin(), q.end(), greater<>()); int l = *max_element(b.begin(), b.begin() + n) + 1; BIT bt(l); vector c(m); int i = 0; for (int j = 0; j < m; j++) { while (i < n && p[i].first >= q[j].first.first) { bt.add(p[i++].second, 1); } c[q[j].second] = bt.sum(min(l, q[j].first.second + 1)); } int r = *max_element(c.begin(), c.end()); if (r == 0) { cout << 0 << endl; } else { for (int j = 0; j < m; j++) { if (c[j] == r) cout << j + 1 << '\n'; } } return 0; }