제출 #1124411

#제출 시각아이디문제언어결과실행 시간메모리
1124411KawakiMeidoPlahte (COCI17_plahte)C++20
160 / 160
371 ms42680 KiB
#include <bits/stdc++.h> #define endl "\n" #define all(x) (x).begin(),(x).end() #define ll long long #define pii pair<int,int> #define piiii pair<pii,pii> #define piiiii pair<piiii,int> #define fi first #define se second #define NAME "LOANGMUC" using namespace std; const int N = 2e5+10; const int INF = 1e9+7; const long long LLINF = 1e18+3; int n,q; void Init(){ } bool CheckSub1(){ return true; } vector<int> nen; int parent[N]; set<int>* st[N]; int ans[N]; vector<int> adj[N]; void DFS(int u){ set<int>* curst = st[u]; for (auto v:adj[u]){ if (v==parent[u]) continue; DFS(v); if (curst == NULL || curst->size()<st[v]->size()){ curst = st[v]; } } for (auto v:adj[u]){ if (v==parent[u]) continue; if (st[v] == curst){ st[v] = NULL; continue; } for (auto x:(*st[v])){ curst->insert(x); } delete st[v]; } if (curst!=st[u]){ for (auto x:(*st[u])){ curst->insert(x); } delete st[u]; st[u] = curst; } ans[u] = st[u]->size(); } struct SegmentTree{ vector<int> ST; vector<int> lazy; int n; SegmentTree(int _n): n(_n){ ST.resize(n*4+10,0); lazy.resize(n*4+10,-1); } void Propagate(int idx){ if (lazy[idx] == -1) return; int val = lazy[idx]; ST[idx*2] = val; lazy[idx*2] = val; ST[idx*2+1] = val; lazy[idx*2+1] = val; lazy[idx] = -1; } void Update(int idx, int l, int r, int x, int y, int val){ if (y<l || r<x) return; if (x<=l && r<=y){ ST[idx] = val; lazy[idx] = val; return; } Propagate(idx); int mid = (l+r)/2; Update(idx*2,l,mid,x,y,val); Update(idx*2+1,mid+1,r,x,y,val); ST[idx] = max(ST[idx*2],ST[idx*2+1]); } int Get(int idx, int l, int r, int x, int y){ if (y<l || r<x) return 0; if (x<=l && r<=y){ return ST[idx]; } Propagate(idx); int mid = (l+r)/2; return max(Get(idx*2,l,mid,x,y),Get(idx*2+1,mid+1,r,x,y)); } }; vector<piiiii> sqr; void SolveSub1(){ cin >> n >> q; for (int i=1; i<=n; i++){ int x1,y1,x2,y2; cin >> x1 >> y1 >> x2 >> y2; nen.push_back(x1); nen.push_back(x2); nen.push_back(y1); nen.push_back(y2); sqr.push_back({{{y1,0},{x1,x2}},i}); sqr.push_back({{{y2,2},{x1,x2}},i}); st[i] = new set<int>; } for (int i=1; i<=q; i++){ int x,y,col; cin >> x >> y >> col; nen.push_back(x); nen.push_back(y); sqr.push_back({{{y,1},{x,x}},col}); } sort(all(nen)); nen.resize(unique(all(nen))-nen.begin()); for (int i=0; i<(int)sqr.size(); i++){ sqr[i].fi.fi.fi = lower_bound(all(nen),sqr[i].fi.fi.fi) - nen.begin() +1; sqr[i].fi.se.fi = lower_bound(all(nen),sqr[i].fi.se.fi) - nen.begin() +1; // if (sqr[i].fi.fi.se !=1){ sqr[i].fi.se.se = lower_bound(all(nen),sqr[i].fi.se.se) - nen.begin() +1; // } } sort(all(sqr)); int sz = (int)nen.size(); SegmentTree ST(sz); int idx = 0; for (int i=1; i<=sz; i++){ while (idx!=(int)sqr.size() && sqr[idx].fi.fi.fi == i){ int tpe = sqr[idx].fi.fi.se; int l = sqr[idx].fi.se.fi; int r = sqr[idx].fi.se.se; int id = sqr[idx].se; ++idx; if (tpe == 0){ int u = ST.Get(1,1,sz,l,r); parent[id] = u; if (u!=0) adj[u].push_back(id); ST.Update(1,1,sz,l,r,id); } if (tpe == 1){ int u = ST.Get(1,1,sz,l,l); if (u!=0) st[u]->insert(id); } if (tpe == 2){ ST.Update(1,1,sz,l,r,parent[id]); } } } // cout << sz << endl; // for (int i=1; i<=n; i++){ // cout << parent[i] << " "; // } // cout << endl; // for (int i=1; i<=n; i++){ // for (auto x:(*st[i])){ // cout << x << " "; // } // cout << endl; // } // for (int i=1; i<=n; i++){ // for (auto x:(adj[i])){ // cout << x << " "; // } // cout << endl; // } for (int i=1; i<=n; i++){ if (parent[i] == 0){ DFS(i); } } // for (auto x:(*st[1])) cout << x << " "; cout << endl; for (int i=1; i<=n; i++){ cout << ans[i] << " "; } cout << endl; } signed main() { // freopen(NAME ".inp","r",stdin); // freopen(NAME ".out","w",stdout); ios_base::sync_with_stdio(0); cin.tie(0); Init(); if (CheckSub1()) return SolveSub1(), 0; 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...