#include #include #include #include #include #ifndef LIN #define LIN (180) #endif using namespace std ; using ll = long long ; using pt = tuple ; vector pts ; struct k2t { k2t(pt *m, ll sv, int uf, k2t *w_, k2t *e_) : mid(m), splitval(sv), usefirst(uf), w(w_), e(e_) {} pt *mid ; ll splitval ; int usefirst ; k2t *w, *e ; } *tree ; k2t *maketree(pt *a, pt *b, int upfirst) { ll n = b - a ; if (n < LIN) return 0 ; sort(a, b, [](auto &a, auto &b) { return get<1>(a)(b) ; }) ; pt *c = a + (n >> 1) ; while (c < b && get<1>(*c) == get<1>(*(c-1))) c++ ; ll sv = c - a ; sort(a, b) ; c = a + (n >> 1) ; while (c < b && get<0>(*c) == get<0>(*(c-1))) c++ ; ll fv = c - a ; if (fv < sv || (fv == sv && !upfirst)) { return new k2t(a+fv, get<0>(a[fv-1]), 1, maketree(a, a+fv, 1), maketree(a+fv, b, 1)) ; } else { sort(a, b, [](auto &a, auto &b) { return get<1>(a)(b) ; }) ; return new k2t(a+sv, get<1>(a[sv-1]), 0, maketree(a, a+sv, 0), maketree(a+sv, b, 0)) ; } } multiset acc ; int searchtree(pt *a, pt *b, ll xlo, ll xhi, ll ylo, ll yhi, k2t *t) { if (t == 0) { while (a < b) { if (xlo <= get<0>(*a) && get<0>(*a) <= xhi && ylo <= get<1>(*a) && get<1>(*a) <= yhi) { auto it = acc.insert(get<2>(*a)) ; if (acc.size() >= 3) { if (it != acc.begin()) it-- ; if (it != acc.begin()) it-- ; auto ha = *it++ ; auto hb = *it++ ; int cnt = 3 ; while (it != acc.end() && cnt > 0) { auto hc = *it++ ; if (hc < ha + hb) return 1 ; ha = hb ; hb = hc ; cnt-- ; } } } a++ ; } return 0 ; } auto m = t->mid ; if (t->usefirst) { if (xlo <= t->splitval && searchtree(a, m, xlo, xhi, ylo, yhi, t->w)) return 1 ; if (xhi > t->splitval && searchtree(m, b, xlo, xhi, ylo, yhi, t->e)) return 1 ; } else { if (ylo <= t->splitval && searchtree(a, m, xlo, xhi, ylo, yhi, t->w)) return 1 ; if (yhi > t->splitval && searchtree(m, b, xlo, xhi, ylo, yhi, t->e)) return 1 ; } return 0 ; } int main() { int n, q ; cin >> n >> q ; pts.resize(n) ; for (int i=0; i> get<0>(pts[i]) >> get<1>(pts[i]) >> get<2>(pts[i]) ; tree = maketree(pts.data(), pts.data()+n, 0) ; for (int i=0; i> x0 >> y0 >> x1 >> y1 ; acc.clear() ; int found = searchtree(pts.data(), pts.data()+n, x0, x1, y0, y1, tree) ; cout << found << endl ; } }