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;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n), b(n), c(n), d(n);
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i] >> c[i] >> d[i];
}
vector<int> x(m), y(m), k(m);
for (int i = 0; i < m; i++) {
cin >> x[i] >> y[i] >> k[i];
}
vector<array<int, 3>> ev;
for (int i = 0; i < n; i++) {
ev.push_back({a[i], i, 0});
ev.push_back({c[i] + 1, ~i, 1});
}
for (int i = 0; i < m; i++) {
ev.push_back({x[i], n + i, 2});
}
sort(ev.begin(), ev.end());
set<array<int, 3>> st;
set<array<int, 3>> rst;
vector<vector<int>> g(n);
vector<set<int>> col(n);
/*for (auto& p : ev) {
int i = p[1];
if (p[2] == 0) {
auto it = st.lower_bound({b[i], -1, -1});
if (it != st.begin()) {
it = prev(it);
if ((*it)[0] < b[i] && (*it)[1] > d[i]) {
g[(*it)[2]].push_back(i);
}
}
st.insert({b[i], d[i], i});
rst.insert({d[i], b[i], i});
}
if (p[2] == 1) {
i = ~i;
st.erase({b[i], d[i], i});
rst.erase({d[i], b[i], i});
}
if (p[2] == 2) {
i -= n;
auto it = rst.lower_bound({y[i], -1, -1});
if (it != rst.end()) {
if ((*it)[0] >= y[i] && (*it)[1] <= y[i]) {
col[(*it)[2]].insert(k[i]);
}
}
}
}*/
vector<int> order(n);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int i, int j) {
return (c[i] - a[i] + 1) * 1LL * (d[i] - b[i] + 1) > (c[j] - a[j] + 1) * 1LL * (d[j] - b[j] + 1);
});
for (int _i = 0; _i < n; _i++) {
for (int _j = _i - 1; _j >= 0; _j--) {
int i = order[_i];
int j = order[_j];
if (a[j] <= a[i] && c[i] <= c[j] && b[j] <= b[i] && d[i] <= d[j]) {
g[j].push_back(i);
break;
}
}
}
for (int i = 0; i < m; i++) {
for (int _j = n - 1; _j >= 0; _j--) {
int j = order[_j];
if (a[j] <= x[i] && x[i] <= c[j] && b[j] <= y[i] && y[i] <= d[j]) {
col[j].insert(k[i]);
break;
}
}
}
vector<bool> root(n, true);
for (int i = 0; i < n; i++) {
for (int j : g[i]) {
root[j] = false;
}
}
vector<int> res(n);
vector<int> where(n);
function<void(int)> Dfs = [&](int v) {
where[v] = v;
for (int u : g[v]) {
Dfs(u);
if (col[where[v]].size() < col[where[u]].size()) {
swap(where[v], where[u]);
}
for (int c : col[where[u]]) {
col[where[v]].insert(c);
}
col[where[u]].clear();
}
res[v] = (int) col[where[v]].size();
};
for (int i = 0; i < n; i++) {
if (root[i]) {
Dfs(i);
}
}
for (int i = 0; i < n; i++) {
cout << res[i] << '\n';
}
return 0;
}
# | 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... |