제출 #1124414

#제출 시각아이디문제언어결과실행 시간메모리
1124414FucKanhPlahte (COCI17_plahte)C++20
0 / 160
409 ms30352 KiB
#include<bits/stdc++.h> #define pii pair<int,int> using namespace std; const int maxn = 8e4 + 2; priority_queue<pii,vector<pii>,greater<pii>> qpin,qpout; pair<pii,pii> rec[maxn]; set<pii> ms; int pa[maxn]; set<int> st[maxn]; tuple<int,int,int> colour[maxn]; vector<int> a[maxn]; int ans[maxn]; vector<pii> DEL[maxn]; void dfs(int u) { for (int v : a[u]) { dfs(v); if (st[v].size() > st[u].size()) swap(st[v],st[u]); for (int val : st[v]) st[u].insert(val); } ans[u] = st[u].size(); } signed main() { cin.tie(0)->sync_with_stdio(0); // freopen("LOANGMUC.INP", "r", stdin); // freopen("LOANGMUC.OUT", "w", stdout); int n,m; cin >> n >> m; for (int i = 1; i <= n; i++) { int x,y; cin >> x >> y; int x2,y2; cin >> x2 >> y2; qpin.push({x,-i}); qpout.push({x2,-i}); rec[i].first = {x,y}; rec[i].second = {x2,y2}; } for (int i = 1; i <= m; i++) { int x,y,c; cin >> x >> y >> c; colour[i] = make_tuple(x,y,c); qpin.push({x,i}); } while (qpin.size()) { // cerr << ":::::: " << qpin.size() << endl; // for (pii tmp : ms) { // cerr << tmp.first << " " << tmp.second << endl; // } if (qpout.empty() || qpin.top().first <= qpout.top().first) { int id = qpin.top().second; qpin.pop(); // cerr << "in: " << id << " " << qpin.size() << endl; if (id > 0) { int x,y,c; tie(x,y,c) = colour[id]; set<pii>::iterator p = ms.lower_bound(make_pair(y,0)); if (p!=ms.end()) { if (y <= rec[p->second].first.second ) continue; st[p->second].insert(c); // cerr << ":: " << p->second << endl; } continue; } id = -id; set<pii>::iterator p = ms.upper_bound(make_pair(rec[id].second.second,0)); if (p!=ms.end()) { pa[id] = p->second; if (rec[id].first.second <= rec[pa[id]].first.second ) continue; a[pa[id]].push_back(id); if (rec[id].first.second > rec[pa[id]].first.second) { ms.insert(make_pair(rec[id].first.second - 1, pa[id])); DEL[id].push_back(make_pair(rec[id].first.second - 1, pa[id])); } } ms.insert(make_pair(rec[id].second.second, id)); } else { int id = qpout.top().second; // cerr << "out: " << id << endl; qpout.pop(); id = -id; for (pii tmp : DEL[id]) { cerr << tmp.second << endl; ms.erase(tmp); } ms.erase(make_pair(rec[id].second.second,id)); // cerr << "done " << rec[id].second.second << " " << id << endl; } } // for (int i = 1; i <= n; i++) { // cerr << i << ": " << pa[i] << endl; // for (int val : st[i]) { // cerr << "::: " << val << endl; // } // } for (int i =1; i <= n; i++) { if (pa[i]==0) dfs(i); } for (int i = 1; i <= n; i++) { cout << ans[i] << '\n'; } }
#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...