1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
| #include <bits/stdc++.h> #define FOE(i, s, t) for (int i = s; i <= t; i++) #define FOR(i, s, t) for (int i = s; i < t; i++) #define K 2300001 #define M 1000000007 #define NINF -2002100100 #define LL long long using namespace std; int n, q; struct P { int x, y, r; }; P p[K]; int cx[2 * K]; struct Q { int sx, ymin, ymax, ex, id; }; Q qu[K]; bool cmpY(P A, P B) { return A.y < B.y; } bool cmpQY(Q A, Q B) { return A.ymin < B.ymin; } int l[4 * K], r[4 * K]; LL a[4 * K]; int h; int sol[K]; void build(int u, int lb, int rb) { a[u] = NINF; if (lb == rb) return; build(l[u] = ++h, lb, (lb + rb) >> 1); build(r[u] = ++h, (lb + rb) / 2 + 1, rb); } void insert(int u, int lb, int rb, int pos, LL val) { if (lb == rb) { a[u] = val; return; } int mid = (lb + rb) >> 1; if (mid >= pos) { insert(l[u], lb, mid, pos, val); } else { insert(r[u], mid + 1, rb, pos, val); } a[u] = max(a[l[u]], a[r[u]]); } LL query(int u, int lb, int rb, int lq, int rq) { if (lq <= lb && rb <= rq) { return a[u]; } if (rb < lq || rq < lb) return NINF; int mid = (lb + rb) >> 1; LL a1 = query(l[u], lb, mid, lq, rq); LL a2 = query(r[u], mid + 1, rb, lq, rq); return max(a1, a2); } int tx[2 * K], head; int findX(int val) { int low = 1, high = head; int res; while (low <= high) { int mid = (low + high) >> 1; if (tx[mid] <= val) { low = mid + 1; res = mid; } else { high = mid - 1; } } return res; } void solve() { scanf("%d%d", &n, &q); FOE(i, 1, n) { int x, y, r; scanf("%d%d%d", &x, &y, &r); p[i].x = x; p[i].y = y - r; p[i].r = r; cx[i] = x; } FOE(i, 1, q) { int px, py, qx, qy, ymin, ymax; scanf("%d%d%d%d%d%d", &px, &py, &qx, &qy, &ymin, &ymax); cx[i + n] = px; cx[i + n + q] = qx; qu[i].sx = min(px, qx); qu[i].ex = max(px, qx); qu[i].ymin = ymin; qu[i].id = i; qu[i].ymax = ymax; } sort(p + 1, p + n + 1, cmpY); sort(qu + 1, qu + q + 1, cmpQY); sort(cx + 1, cx + n + 2 * q + 1); int last; FOE(i, 1, n + 2 * q) { if (i == 1 || cx[i] != last) { head++; tx[head] = cx[i]; last = cx[i]; } } build(0, 1, head); int ptr = 1; FOE(i, 1, q) { int cmin = qu[i].ymin; while (ptr <= n && p[ptr].y <= cmin) { int qx = findX(p[ptr].x); insert(0, 1, head, qx, p[ptr].y + p[ptr].r * 2); ptr++; } int qsx = findX(qu[i].sx); int qex = findX(qu[i].ex); int id = qu[i].id; sol[id] = (query(0, 1, head, qsx, qex) < qu[i].ymax); } FOE(i, 1, q) { if (sol[i]) puts("YES"); else puts("NO"); } } int main() { solve(); }
|