Submission #1124568

#TimeUsernameProblemLanguageResultExecution timeMemory
1124568FucKanhPlahte (COCI17_plahte)C++20
0 / 160
283 ms38116 KiB
#include<bits/stdc++.h> #define ll long long #define int ll #define pii pair<int,int> using namespace std; class IT { vector<int> t; int _n; public: void init(int n) { _n = n; t.resize((n+2)*4,0); } void update(int v, int l, int r, int L, int R, int c) { if (l==L && r == R) { t[v] = c; // cerr << "update: " << v << " " << l << " " << r << ": " << c << endl; return; } if (L > R) return; int mid = l + r >> 1; update(v*2,l,mid,L,min(mid,R),c); update(v*2+1,mid+1,r,max(L,mid+1),R,c); } int get(int v, int l, int r, int pos) { if (l==r) return t[v]; int mid = l + r >> 1; if (pos <= mid) { int val = get(v*2,l,mid,pos); if (val==0) return t[v]; return val; } int val = get(v*2+1,mid+1,r,pos); if (val==0) return t[v]; return val; } }; const int maxn = 8e4 + 2; int pa[maxn],ans[maxn]; set<int> st[maxn]; pii rec[maxn],colour[maxn]; vector<int> a[maxn]; map<int,int> mp; 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(); } void solve() { int n,m; cin >> n >> m; vector<int> vec; priority_queue<pii,vector<pii>,greater<pii>> qin,qout; for (int i = 1; i <= n; i++) { int x1,y1,x2,y2; cin >> x1 >> y1 >> x2 >> y2; rec[i] = {y1,y2}; vec.push_back(y1); vec.push_back(y2); qin.push({x1,-i}); qout.push({x2,-i}); } for (int i = 1; i <= m; i++) { int x1,y1,c; cin >> x1 >> y1 >> c; qin.push({x1,i}); vec.push_back(y1); colour[i] = {y1,c}; } sort(vec.begin(),vec.end()); int pre = -1,cnt=0; for (int val : vec) { if (val==pre) continue; pre = val; cnt++; mp[val] = cnt; } for (int i = 1; i <= n; i++) rec[i] = make_pair(mp[rec[i].first], mp[rec[i].second]); for (int i = 1; i <= m; i++) colour[i].first = mp[colour[i].first]; IT tree; tree.init(cnt); while (qin.size() && qout.size()) { if (qin.top().first <= qout.top().first) { int u = qin.top().second; // cerr << "tin: " << u << endl; qin.pop(); if (u > 0) { int pos,c; tie(pos,c) = colour[u]; // cerr << pos << endl; int cha = tree.get(1,1,cnt, pos); if (cha) st[cha].insert(c); } else { u = -u; int l,r; tie(l,r) = rec[u]; // cerr << l << " " << r << endl; pa[u] = tree.get(1,1,cnt,l); assert( tree.get(1,1,cnt,l) == tree.get(1,1,cnt,r)); a[pa[u]].push_back(u); // cerr << u << " cha: " << cha << endl; tree.update(1,1,cnt,l,r,u); } } else { int u = qout.top().second; // cerr << "tout: " << u << endl; qout.pop(); u = -u; int l,r;tie(l,r) = rec[u]; tree.update(1,1,cnt,l,r,pa[u]); } } // for (int i =1; i <= n; i++) { // cerr << i << " " << pa[i] << endl; // } for (int i = 1; i <= n; i++) { if (pa[i] == 0) dfs(i); cout << ans[i] << '\n'; } } signed main() { cin.tie(0) -> sync_with_stdio(0); solve(); 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...