#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,bmi,bmi2,lzcnt,popcnt,tune=native")
using namespace std;
typedef long long ll;
void solve() {
int n, q; cin >> n >> q;
int sz = (n + 7) / 8 * 8;
array<int, 3> p[sz];
for (int i = 0; i < n; ++i) {
cin >> p[i][0] >> p[i][1] >> p[i][2];
}
for (int i = n; i < sz; ++i) p[i][0] = p[i][1] = p[i][2] = -1;
sort(p, p+sz);
for (int i = 0; i < q; ++i) {
int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
vector<unsigned> tmp[8];
int ct[8] = {0};
for (int j = 0; j < sz; j += 8) {
if (x1 > p[j + 7][0]) continue;
// Process pairs
for (int k = 0; k < 16; ++k) {
if (x1 <= p[j + k][0] && p[j + k][0] <= x2 && y1 <= p[j + k][1] && p[j + k][1] <= y2) {
tmp[k].push_back(p[j + k][2]);
++ct[k];
}
}
// Combined count check
if (ct[0] + ct[1] + ct[2] + ct[3] + ct[4] + ct[5] + ct[6] + ct[7] > 60) { cout << "1\n"; continue; }
for (int j = 1; j < 8; ++j) for (auto z : tmp[j]) tmp[0].push_back(z);
sort(tmp[0].begin(), tmp[0].end());
bool ok = 1;
for (int j = 0; j < (int)(tmp[0].size()) - 2; ++j) {
if (tmp[0][j] + tmp[0][j+1] > tmp[0][j+2]) {
cout << "1\n";
ok = 0;
break;
}
}
if (ok) cout << "0\n";
}
}
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
int t = 1;
// cin >> t;
while (t--) solve();
}