Submission #985980

#TimeUsernameProblemLanguageResultExecution timeMemory
985980MighilonPlahte (COCI17_plahte)C++17
0 / 160
141 ms23100 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){ 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); vector<pair<pi, int>> events; vector<shot> p(m); vi contains(n, -1); colors.resize(n); 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, 0}, i}); events.pb({{r[i].x, 2}, i}); } F0R(i, m){ cin >> p[i].x >> p[i].y >> p[i].c; events.pb({{p[i].x, 1}, i}); } 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 + m){ int id = events[i].s; if(events[i].f.s == 1){ auto it = active.upper_bound({{p[id].x, p[id].y}, 0}); dbg(active) if(it == active.begin()) continue; dbg(p[id].x, p[id].y); dbg(*it) it = prev(it); dbg(active) int j = it->s; dbg(*it) if(it != active.end() && r[j].a <= p[id].x && r[j].b <= p[id].y && r[j].x >= p[id].x && r[j].y >= p[id].y){ colors[it->s].insert(p[id].c); } continue; } if(events[i].f.f == r[id].a && events[i].f.s == 0){ auto it = active.insert({{r[id].a, r[id].b}, id}).f; 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}); } } 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(colors) */ /* dbg(contains); */ 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...