Submission #137911

#TimeUsernameProblemLanguageResultExecution timeMemory
137911mariusnicoliPlahte (COCI17_plahte)C++14
0 / 160
363 ms342744 KiB
#include <fstream> ///#include <iostream> #include <deque> #include <set> #include <vector> #include <algorithm> #define INF 1000000001 using namespace std; ifstream cin("plahte.in"); ofstream cout("plahte.out"); struct foaie { int x1; int y1; int x2; int y2; }; struct bila { int x; int y; int c; }; struct eveniment { int tip; /// 1 incepe dreptunghi, 2 bila, 3 se termina dreptunghi int x; int ind; }; deque<int> A[500000]; /// coada cu indice de /// evenimente, de unde obtin dreptunghiul foaie f[80001]; bila b[80001]; eveniment e[240001]; set <int> culori[80010]; vector <int> L[80010]; int Y[240001]; int dimY, maxim, indice, n, m, k; int sol[80010]; int T[80010]; int cmp (const eveniment &a, const eveniment &b) { if (a.x != b.x) return a.x < b.x; else return a.tip < b.tip; } void intra(int nod, int st, int dr, int a, int b, int m) { if (a <= st && dr <= b) { A[nod].push_back(m); } else { int mid = (st + dr)/2; if (a <= mid) intra(2*nod, st, mid, a, b, m); if (b > mid) intra(2*nod+1, mid+1, dr, a, b, m); } } void iese(int nod, int st, int dr, int a, int b, int m) { if (a <= st && dr <= b) { A[nod].pop_back(); } else { int mid = (st + dr)/2; if (a <= mid) iese(2*nod, st, mid, a, b, m); if (b > mid) iese(2*nod+1, mid+1, dr, a, b, m); } } set<int> ally; int getPoz(int y) { int st = 1,dr = dimY; while (st <= dr) { int mid = (st+dr)/2; if (Y[mid] == y) return mid; if (Y[mid] > y) dr = mid-1; else st = mid+1; } return -1; } void getLast(int nod, int st, int dr, int y) { if (st <= dr) { if (A[nod].size()) if (T[A[nod].back()] > maxim) { maxim = T[A[nod].back()]; indice = A[nod].back(); } if (st == dr) return; int mid = (st + dr)/2; if (y <= mid) getLast(2*nod, st, mid, y); else getLast(2*nod+1, mid+1, dr, y); } } void dfs(int nod) { int poz = nod; for (int i=0;i<L[nod].size();i++) { int vecin = L[nod][i]; dfs(vecin); if (culori[poz].size() < culori[vecin].size()) { swap(poz, vecin); } for(set<int>::iterator it = culori[vecin].begin(); it != culori[vecin].end(); it++) { culori[poz].insert(*it); } } sol[nod] = culori[poz].size(); swap(culori[nod], culori[poz]); } int main () { cin>>n>>m; for (int i=0;i<=n;i++) { if (i == 0) { f[i].x1 = -INF; f[i].y1 = -INF; f[i].x2 = INF; f[i].y2 = INF; } else cin>>f[i].x1>>f[i].y1>>f[i].x2>>f[i].y2; ally.insert(f[i].y1); ally.insert(f[i].y2); k++; e[k].tip = 1; e[k].x = f[i].x1; e[k].ind = i; k++; e[k].tip = 3; e[k].x = f[i].x2; e[k].ind = i; } for (int i=1;i<=m;i++) { cin>>b[i].x>>b[i].y>>b[i].c; ally.insert(b[i].y); k++; e[k].tip = 2; e[k].x = b[i].x; e[k].ind = i; } sort(e+1, e+k+1, cmp); for (set<int>::iterator it = ally.begin(); it != ally.end(); it++) Y[++dimY] = *it; for (int i=1;i<=k;i++) { if (e[i].tip == 1) { /// intra dreptunghi if (e[i].x != -INF) { maxim = -1; getLast(1, 1, dimY, getPoz(f[e[i].ind].y1)); ///T[e[i].ind] = indice; L[indice].push_back(e[i].ind); } T[e[i].ind] = i; intra(1, 1, dimY, getPoz(f[e[i].ind].y1), getPoz(f[e[i].ind].y2), e[i].ind); } else if (e[i].tip == 3) { iese(1, 1, dimY, getPoz(f[e[i].ind].y1), getPoz(f[e[i].ind].y2), e[i].ind); } else { /// bila maxim = -1; getLast(1, 1, dimY, getPoz(b[e[i].ind].y)); culori[indice].insert(b[e[i].ind].c); } } /// avem un vector de /** cout<<"\n"; for(vector <int>::iterator it = L[0].begin(); it != L[0].end(); it++) cout<<*it<<"\n"; cout<<L[0].size()<<" "<<L[1].size()<<" "<<L[2].size(); **/ /** for (int i=0;i<=n;i++) cout<<culori[i].size()<<"\n"; **/ dfs(0); for (int i=1;i<=n;i++) cout<<sol[i]<<"\n"; return 0; }

Compilation message (stderr)

plahte.cpp: In function 'void dfs(int)':
plahte.cpp:107:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0;i<L[nod].size();i++) {
                  ~^~~~~~~~~~~~~~
#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...