This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ld long  double
#define ull unsigned long long
#define ii pair <int, int>
#define ill pair <ll, ll>
#define ild pair <ld, ld>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define file "test"
using namespace std;
const int N = 1e5 + 2;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll base = 311;
const int BLOCK_SIZE = 400;
int n, m;
int par[N], in[N], ans[N];
vector <int> adj[N];
set <int> g[N];
set <pair <ii, int>> h;
int parent(int v) {
    auto it = h.lower_bound({{v, 0}, 0});
    if (it == h.end()) return 0;
    int t = (*it).fi.se, id = (*it).se;
    if (t == 1) return id;
    return par[id];
}
set <int> dfs(int u, int p) {
    set <int> res;
    for (int k: g[u]) res.insert(k);
    for (int v: adj[u]) if (v != p) {
        set <int> tmp = dfs(v, u);
        if (res.size() < tmp.size()) swap(res, tmp);
        for (int k: tmp) res.insert(k);
    }
    ans[u] = res.size();
    return res;
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    vector <pair <ii, ii>> rec;
    vector <pair <ii, int>> event, ball;
    for (int i = 0; i < n; i ++) {
        int x, y, u, v;
        cin >> x >> y >> u >> v;
        rec.push_back({{x, y}, {u, v}});
        event.push_back({{x, -1}, i});
        event.push_back({{u, 1}, i});
    }
    for (int i = 0; i < m; i ++) {
        int x, y, k;
        cin >> x >> y >> k;
        ball.push_back({{x, y}, k});
        event.push_back({{x, 0}, i});
    }
    sort(all(event));
    for (pair <ii, int> e: event) {
        auto [x, t] = e.fi;
        int i = e.se;
        if (t == -1) {
            if (!h.empty())
                par[i + 1] = parent(rec[i].fi.se);
            h.insert({{rec[i].fi.se, -1}, i + 1});
            h.insert({{rec[i].se.se, 1}, i + 1});
        }
        else if (t == 1) {
            h.erase({{rec[i].fi.se, -1}, i + 1});
            h.erase({{rec[i].se.se, 1}, i + 1});
        }
        else if (!h.empty()) {
            int id = parent(ball[i].fi.se);
            g[id].insert(ball[i].se);
        }
    }
    for (int u = 1; u <= n; u ++) {
        in[u] += par[u] != 0;
        adj[u].push_back(par[u]);
        adj[par[u]].push_back(u);
    }
    for (int u = 1; u <= n; u ++)
        if (!in[u]) dfs(u, 0);
    for (int i = 1; i <= n; i ++)
        cout << ans[i] << '\n';
}
/*
     /\_/\ zzZ
    (= -_-)
    / >u  >u
*/
Compilation message (stderr)
plahte.cpp: In function 'int main()':
plahte.cpp:70:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   70 |         auto [x, t] = e.fi;
      |              ^| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |