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>
using namespace std;
const int N = 8e4 + 1;
vector<pair<int,pair<int,int>>> A;
int B[N];
int D[N];
int Y[N];
int col[N];
vector<int> adj[N];
int ans[N];
int par[N];
map<int,pair<int,int>> active;
set<int> hits[N];
void dfs(int u, int p) {
for(int i : adj[u]) {
dfs(i,u);
if (hits[i].size() > hits[u].size()) swap(hits[i],hits[u]);
for (int j : hits[i]) hits[u].insert(j);
}
ans[u] = hits[u].size();
}
int main() {
int n,m; cin >> n >> m;
int a,b,c,d;
for(int i = 0; i < n; i++) {
cin >> a >> b >> c >> d;
B[i] = b;
D[i] = d;
A.push_back({a,{i,1}});
A.push_back({c,{i,3}});
}
for(int i = 0; i < m; i++) {
cin >> a >> b >> c;
col[i] = c;
Y[i] = b;
A.push_back({a,{i,2}});
}
sort(begin(A),end(A),[&](auto i, auto j) {
return i.first == j.first ? i.second.second < j.second.second : i.first < j.first;
});
fill(par,par+n,-1);
for(auto e : A) {
if (e.second.second == 1) {
auto f = active.upper_bound(D[e.second.first]);
if (f != active.end()) { // there is a point here
if (f->second.second == 1) {// this is the top of another guy - parent
adj[f->second.first].push_back(e.second.first);
par[e.second.first] = f->second.first;
} else {//this is the bottom of another guy - if he has a parent then they must have the same parent
if (par[f->second.first] != -1) {
adj[par[f->second.first]].push_back(e.second.first);
par[e.second.first] = par[f->second.first];
}
}
}
active[D[e.second.first]] = {e.second.first,1};
active[B[e.second.first]] = {e.second.first,-1};
} else if (e.second.second == 3) {
active.erase(D[e.second.first]);active.erase(B[e.second.first]);
} else {
auto f = active.upper_bound(Y[e.second.first]-1);
if (f!= active.end()) { // there might be a hit
if (f->second.second == 1) {
hits[f->second.first].insert(col[e.second.first]);
} else {
if (par[f->second.first] != -1) {
hits[par[f->second.first]].insert(col[e.second.first]);
}
}
}
}
}
for(int i = 0; i < n; i++) {
if (par[i] == -1) dfs(i,-1);
}
for(int i = 0; i < n; i++) {
cout << ans[i] << endl;
}
}
# | 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... |