#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #if 1 #define PRINT(x) { cout << #x << ": " << (x) << endl; } #define PRINT_CONTAINER(x) { cout << #x << ": "; \ for (size_t ix = 0; ix < (x).size(); ++ix) cout << (x)[ix] << ", "; \ cout << endl; } #else #define PRINT(x) #define PRINT_CONTAINER(x) #endif typedef pair p; int n, m; vector

member; vector

mentai_a; vector

mentai_b; vector

vote; int main(int argc, char *argv[]) { scanf("%d", &n); for (int i = 0; i < n; ++i) { int a, b; scanf("%d%d", &a, &b); member.push_back(p(a, b)); } scanf("%d", &m); for (int i = 0; i < m; ++i) { int a, b; scanf("%d%d", &a, &b); mentai_a.push_back(p(a, i)); mentai_b.push_back(p(b, i)); vote.push_back(p(0, i)); } sort(mentai_a.begin(), mentai_a.end()); sort(mentai_b.begin(), mentai_b.end()); for (int i = 0; i < n; ++i) { auto it_a = upper_bound(mentai_a.begin(), mentai_a.end(), p(member[i].first+1, 0)); set fav_a; for (auto it = mentai_a.begin(); it != it_a; ++it) { // cout << i << ",a " << it->second << it->first << endl; fav_a.insert(it->second); } auto it_b = lower_bound(mentai_b.begin(), mentai_b.end(), p(member[i].second, 0)); set fav_b; for (auto it = it_b; it != mentai_b.end(); ++it) { // cout << i << ",b " << it->second << endl; fav_b.insert(it->second); } vector fav; set_intersection(fav_a.begin(), fav_a.end(), fav_b.begin(), fav_b.end(), back_inserter(fav)); for (int v : fav) { ++vote[v].first; } } sort(vote.begin(), vote.end()); reverse(vote.begin(), vote.end()); // for (auto v : vote) // { // cout << v.first << ", " << v.second << endl; // } int vmax = vote[0].first; if (vmax == 0) { puts("0"); return 0; } vector vv; for (int i = 0; i < m; ++i) { if (vote[i].first != vmax) break; vv.push_back(vote[i].second); } sort(vv.begin(), vv.end()); for (auto v : vv) { printf("%d\n", v + 1); } return 0; }