#include<bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
const int maxn = 8e4 + 2;
priority_queue<pii,vector<pii>,greater<pii>> qpin,qpout;
pair<pii,pii> rec[maxn];
set<pii> ms;
int pa[maxn];
set<int> st[maxn];
tuple<int,int,int> colour[maxn];
vector<int> a[maxn];
int ans[maxn];
vector<pii> DEL[maxn];
void dfs(int u) {
for (int v : a[u]) {
dfs(v);
if (st[v].size() > st[u].size()) swap(st[v],st[u]);
for (int val : st[v]) st[u].insert(val);
}
ans[u] = st[u].size();
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
// freopen("LOANGMUC.INP", "r", stdin);
// freopen("LOANGMUC.OUT", "w", stdout);
int n,m; cin >> n >> m;
for (int i = 1; i <= n; i++) {
int x,y; cin >> x >> y;
int x2,y2; cin >> x2 >> y2;
qpin.push({x,-i});
qpout.push({x2,-i});
rec[i].first = {x,y};
rec[i].second = {x2,y2};
}
for (int i = 1; i <= m; i++) {
int x,y,c; cin >> x >> y >> c;
colour[i] = make_tuple(x,y,c);
qpin.push({x,i});
}
while (qpin.size()) {
if (qpin.top() <= qpout.top()) {
int id = qpin.top().second;
qpin.pop();
// cerr << "in: " << id << endl;
if (id > 0) {
int x,y,c; tie(x,y,c) = colour[id];
set<pii>::iterator p = ms.lower_bound(make_pair(y,0));
if (p!=ms.end()) {
st[p->second].insert(c);
// cerr << ":: " << p->second << endl;
}
continue;
}
id = -id;
set<pii>::iterator p = ms.upper_bound(make_pair(rec[id].second.second,0));
if (p!=ms.end()) {
pa[id] = p->second;
a[pa[id]].push_back(id);
if (rec[id].first.second > rec[pa[id]].first.second) {
ms.insert(make_pair(rec[id].first.second - 1, pa[id]));
DEL[id].push_back(make_pair(rec[id].first.second - 1, pa[id]));
}
}
ms.insert(make_pair(rec[id].second.second, id));
}
else {
int id = qpout.top().second;
// cerr << "out: " << id << endl;
qpout.pop();
for (pii tmp : DEL[id]) {
ms.erase(ms.find(tmp));
}
ms.erase(ms.find(make_pair(rec[id].second.second,id)));
}
}
// for (int i = 1; i <= n; i++) {
// cerr << i << ": " << pa[i] << endl;
// for (int val : st[i]) {
// cerr << "::: " << val << endl;
// }
// }
for (int i =1; i <= n; i++) {
if (pa[i]==0) dfs(i);
}
for (int i = 1; i <= n; i++) {
cout << ans[i] << '\n';
}
}
# | 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... |