Submission #854554

#TimeUsernameProblemLanguageResultExecution timeMemory
854554wakandaaaPlahte (COCI17_plahte)C++17
160 / 160
176 ms47556 KiB
#include <bits/stdc++.h> #define fi first #define se second #define all(x) x.begin(), x.end() #define getbit(x, i) (((x) >> (i)) & 1) #define bit(x) (1 << (x)) #define file "" using namespace std; mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count()); long long rand(long long l, long long r) { return l + rd() % (r - l + 1); } const int N = 2e5 + 5; const int mod = 1e9 + 7; // 998244353; const int inf = INT_MAX; const long long llinf = LLONG_MAX; const int lg = 25; // lg + 1 template<class X, class Y> bool minimize(X &a, Y b) { return a > b ? (a = b, true) : false; } template<class X, class Y> bool maximize(X &a, Y b) { return a < b ? (a = b, true) : false; } template<class X, class Y> bool add(X &a, Y b) { a += b; while (a >= mod) a -= mod; while (a < 0) a += mod; return true; } int n, m; vector<int> adj[N]; int par[N]; int ans[N]; set<int> col[N]; set<int> dfs(int u, int p) { set<int> cur; for (auto i : col[u]) cur.insert(i); for (int v : adj[u]) if (v != p) { auto nxt = dfs(v, u); if ((int) nxt.size() > (int) cur.size()) swap(nxt, cur); for (auto i : nxt) cur.insert(i); } ans[u] = cur.size(); return cur; } // typedef #define OPEN -1 #define CLOSE 1 #define POINT 0 typedef tuple<int, int, int> event; vector<event> events; // [x, type, id] set<event> s; // [y, type, id] struct archi { int x, y, u, v; } a[N]; struct point { int x, y, c; } b[N]; int idx[N]; int getpar(int y) { auto it = s.lower_bound({y, 0, 0}); if (it == s.end()) return 0; int type = get<1>(*it); int id = get<2>(*it); if (type == OPEN) return par[id]; return id; } int main() { ios::sync_with_stdio(false); cin.tie(0); // freopen(file".inp", "r",stdin); // freopen(file".out", "w",stdout); cin >> n >> m; for (int i = 1; i <= n; ++i) { int x, y, u, v; cin >> x >> y >> u >> v; a[i] = {x, y, u, v}; events.push_back({x, -1, i}); events.push_back({u, 1, i}); } for (int i = 1; i <= m; ++i) { int x, y, c; cin >> x >> y >> c; b[i] = {x, y, c}; events.push_back({x, 0, i}); } sort(all(events)); for (auto [x, type, id] : events) { if (type == OPEN) { par[id] = getpar(a[id].y); s.insert({a[id].y, -1, id}); s.insert({a[id].v, 1, id}); } if (type == POINT) { idx[id] = getpar(b[id].y); col[idx[id]].insert(b[id].c); } if (type == CLOSE) { s.erase({a[id].y, -1, id}); s.erase({a[id].v, 1, id}); } } for (int i = 1; i <= n; ++i) { adj[i].push_back(par[i]); adj[par[i]].push_back(i); } dfs(0, -1); 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...