Submission #1127130

#TimeUsernameProblemLanguageResultExecution timeMemory
1127130MinhKienPlahte (COCI17_plahte)C++17
0 / 160
2096 ms47604 KiB
#include <unordered_map> #include <algorithm> #include <iostream> #include <vector> #include <set> using namespace std; const int N = 2e5 + 1; int n, m, ans[N], par[N]; set <int> s[N]; vector <int> v[N], Y; vector < pair < pair <int, int>, int > > events; bool IsRoot[N]; struct SegmentTree { int val[N << 2], lazy[N << 2]; void change (int id, int VAL) { val[id] = lazy[id] = VAL; } void down(int id) { if (lazy[id] == -1) return; change(id << 1, lazy[id]); change(id << 1 | 1, lazy[id]); lazy[id] = -1; } void update(int l, int r, int A, int b, int VAL, int id) { if (l > b || r < A) return; if (l >= A && r <= b) { val[id] = lazy[id] = VAL; return; } int mid = (l + r) >> 1; down(id); update(l, mid, A, b, VAL, id << 1); update(mid + 1, r, A, b, VAL, id << 1 | 1); } int get(int l, int r, int A, int id) { if (l == r) return val[id]; int mid = (l + r) >> 1; down(id); if (A <= mid) return get(l, mid, A, id << 1); return get(mid + 1, r, A, id << 1 | 1); } } seg; struct rect { int x1, y1, x2, y2; int id, k; void input(int i) { if (i <= n) { cin >> x1 >> y1 >> x2 >> y2; k = -1; } else { cin >> x1 >> y1 >> k; x2 = x1; y2 = y1; } Y.push_back(y1); Y.push_back(y2); id = i; } void output() { cout << x1 << " " << y1 << " " << x2 << " " << y2 << "\n"; } bool in (int l, int r, int u) { return u >= l && u <= r; } bool rect_in (rect o) { return in(x1, x2, o.x1) && in(x1, x2, o.x2) && in(y1, y2, o.y1) && in(y1, y2, o.y2); } } a[N]; bool cmp (rect x, rect y) { if (pair <int, int>(x.x1, x.y1) == pair <int, int>(y.x1, y.y1)) return pair <int, int>(x.x2, x.y2) < pair <int, int>(y.x2, y.y2); return pair <int, int>(x.x1, x.y1) < pair <int, int>(y.x1, y.y1); } unordered_map <int, int> ID; int GetID(int p) { return ID[p]; } void DFS(int u) { if (a[u].k != -1) { s[u].insert(a[u].k); } for (int z: v[u]) { DFS(z); if (s[u].size() > s[z].size()) s[u].swap(s[z]); for (int j: s[z]) s[u].insert(j); s[z].clear(); } ans[a[u].id] = s[u].size(); } int main() { cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i <= n + m; ++i) { a[i].input(i); IsRoot[i] = true; } sort(Y.begin(), Y.end()); Y.erase(unique(Y.begin(), Y.end()), Y.end()); for (int i = 0; i < Y.size(); ++i) { ID[Y[i]] = i + 1; } sort(a + 1, a + n + m + 1, cmp); for (int i = 1; i <= n + m; ++i) { events.push_back(pair < pair <int, int>, int >(pair <int, int>(a[i].x1, a[i].y1), i)); events.push_back(pair < pair <int, int>, int >(pair <int, int>(a[i].x2, a[i].y2), -i)); } sort(events.begin(), events.end()); int j = 0; for (int i = 1; i <= n + m; ++i) { while (j < events.size() && events[j].first < pair <int, int>(a[i].x1, a[i].y1)) { int cur = abs(events[j].second); if (events[j].second > 0) { seg.update(1, Y.size(), GetID(a[cur].y1), GetID(a[cur].y2), cur, 1); } else { int ph = par[cur]; if (ph != 0) seg.update(1, Y.size(), GetID(a[ph].y1), GetID(a[ph].y2), ph, 1); else seg.update(1, Y.size(), GetID(a[cur].y1), GetID(a[cur].y2), 0, 1); } ++j; } int k = seg.get(1, Y.size(), GetID(a[i].y1), 1); if (k != 0) { par[i] = k; v[k].push_back(i); IsRoot[i] = false; } } for (int i = 1; i <= n + m; ++i) { if (IsRoot[i]) { DFS(i); } } for (int i = 1; i <= n; ++i) { cout << ans[i] << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...