Submission #985912

#TimeUsernameProblemLanguageResultExecution timeMemory
985912MighilonPlahte (COCI17_plahte)C++17
0 / 160
162 ms32624 KiB
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG #include "../Library/debug.h" #else #define dbg(x...) /* #define cin fin */ /* #define cout fout */ /* const string FILE_NAME = "hillwalk"; ifstream fin(FILE_NAME + ".in"); ofstream fout(FILE_NAME + ".out"); */ #endif typedef long long ll; typedef long double ld; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define F0R(i, a) for (int i = 0; i < (a); ++i) #define FORd(i, a, b) for (int i = (b) - 1; i >= (a); --i) #define F0Rd(i, a) for (int i = (a) - 1; i >= 0; --i) #define trav(a, x) for (auto& a : x) #define f first #define s second #define pb push_back #define sz(x) (int)(x).size() #define all(x) x.begin(), x.end() const char nl = '\n'; const int INF = 1e9 + 10000; const ll MOD = 1e9 + 7; const int mxN = 1e6 + 1; struct rectangle{ int a, b, x, y, idx; }; struct shot{ int x, y, c; }; vector<vi> adj; vector<set<int>> colors; vi mag; vector<bool> vis; void dfs(int v, int p = -1){ dbg(v); vis[v] = true; trav(u, adj[v]){ if(u == p) continue; dfs(u, v); if(sz(colors[v]) > sz(colors[u])){ trav(x, colors[u]) colors[v].insert(x); } else{ swap(colors[v], colors[u]); trav(x, colors[u]) colors[v].insert(x); } } mag[v] = sz(colors[v]); } void solve(){ int n, m; cin >> n >> m; vector<rectangle> r(n); vpi events; vector<shot> p(m); vi contains(n, -1); F0R(i, n){ cin >> r[i].a >> r[i].b >> r[i].x >> r[i].y; r[i].idx = i; events.pb({r[i].a, i}); events.pb({r[i].x, i}); } F0R(i, m){ cin >> p[i].x >> p[i].y >> p[i].c; } sort(all(events)); auto set_cmp = [](pair<pi, int> a, pair<pi, int> b){ if(a.f.s == b.f.s) return a.f.f < b.f.f; return a.f.s < b.f.s; }; set<pair<pi, int>, decltype(set_cmp)> active(set_cmp); /* dbg(events); */ F0R(i, 2 * n){ int id = events[i].s; dbg(active); if(events[i].f == r[id].a){ auto it = active.insert({{r[id].a, r[id].b}, id}).f; dbg(*it, it == active.begin()); if(it != active.begin() && r[prev(it)->s].y > r[id].y){ contains[id] = prev(it)->s; } } else{ active.erase({{r[id].a, r[id].b}, id}); } } F0R(i, n){ active.insert({{r[i].a, r[i].b}, i}); active.insert({{r[i].x, r[i].y}, i}); } colors.resize(n); F0R(i, m){ auto it = active.lower_bound({{p[i].x, p[i].y}, 0}); /* dbg(*it, it == active.end()); */ int id = it->s; if(it != active.end() && r[id].a <= p[i].x && r[id].b <= p[i].y && r[id].x >= p[i].x && r[id].y >= p[i].y){ colors[it->s].insert(p[i].c); } } dbg(colors) dbg(contains) adj.resize(n); mag.resize(n); F0R(i, n){ if(contains[i] != -1){ adj[i].pb(contains[i]); adj[contains[i]].pb(i); } } vis.resize(n); F0R(i, n){ if(vis[i] == false && contains[i] == - 1) dfs(i); } dbg(mag); dbg(colors); trav(x, mag) cout << x << nl; } int32_t main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int TC = 1; /* cin >> TC; */ while(TC--){ solve(); /* test(); */ } 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...