#include #include using namespace std; int Pra[128][4], Sni[128][4]; int n, m; bool innp(int x, int y, int *inwhat) { return (x >= inwhat[0] && x <= inwhat[2] && y >= inwhat[1] && y <= inwhat[3]); } vector inside(int *what, int *inwhat) { vector a; if (innp(what[0], what[1], inwhat)) a.push_back(0); if (innp(what[2], what[1], inwhat)) a.push_back(1); if (innp(what[0], what[3], inwhat)) a.push_back(2); if (innp(what[2], what[3], inwhat)) a.push_back(3); return a; } bool BSPTree(int x1, int y1, int x2, int y2) { bool vert[4] = {false}; for (int i = 0; i < m; i++) { //int *s = Sni[m]; int t[4] = {x1, y1, x2, y2}; vector p = inside(t, Sni[i]); // is t in s? if (p.size()==4) return true; for (int i = 0; i < p.size(); i++) vert[p[i]] = true; } for (int i = 0 ; i < 4; i++) if (!vert[i]) return false; int mx = (x1+x2)/2; int my = (y1+y2)/2; bool check[4] = {true, true, true, true}; if (mx == x1) { check[1] = check[3] = false; } if (my == y1) { check[2] = check[3] = false; } bool res = BSPTree(x1, y1, mx, my); if (check[1]) res = res && BSPTree(mx+1, y1, x2, my); if (check[2]) res = res && BSPTree(x1, my+1, mx, y2); if (check[3]) res = res && BSPTree(mx+1, my+1, x2, y2); return res; } bool ok(int k) { return BSPTree(Pra[k][0], Pra[k][1], Pra[k][2], Pra[k][3]); } int main(void) { //freopen("d.in", "rt", stdin); do { scanf("%d%d", &n, &m); if (n||m) { for (int i = 0; i < n; i++) scanf("%d%d%d%d", Pra[i], Pra[i]+1, Pra[i]+2, Pra[i]+3); for (int i = 0; i < m; i++) scanf("%d%d%d%d", Sni[i], Sni[i]+1, Sni[i]+2, Sni[i]+3); vector o; for (int i = 0; i < n; i++) { if (ok(i)) o.push_back(i); } for (int i = 0; i < o.size(); i++) { printf("%d%s", o[i] + 1, i == o.size()-1?"":" "); } printf("\n"); } } while(n||m); return 0; }