Submission #1228669

#TimeUsernameProblemLanguageResultExecution timeMemory
1228669kfhjadPlahte (COCI17_plahte)C++20
0 / 160
2096 ms19792 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MX = 1E5; vector<int> adj[MX]; set<int> cols[MX]; int totalColours[MX]; bool visited[MX]; void dfs(int node) { if (visited[node]) return; visited[node] = true; for (auto u : adj[node]) { dfs(u); if (cols[node].size() < cols[u].size()) swap(cols[node], cols[u]); cols[node].insert(cols[u].begin(), cols[u].end()); } totalColours[node] = cols[node].size(); } // v = y1, y2, index void add(auto& s, auto& v) { auto it = s.upper_bound({v[0] + 1, (int)2E9, 0}); --it; auto temp = *it; s.erase(it); s.insert(v); s.insert({temp[0], v[0], temp[2]}); s.insert({v[1], temp[1], temp[2]}); adj[temp[2]].push_back(v[2]); } // v = y1, y2, index void erase(auto& s, auto& v) { auto it = s.find(v); assert(it != s.end()); it = s.erase(it); --it; auto temp = *it; it = s.erase(it); temp[1] = (*it)[1]; s.erase(it); s.insert(temp); } int main() { cin.tie(NULL) -> sync_with_stdio(false); int N, M; cin >> N >> M; // x, y1, y2, index // [y1, y2) vector<array<int, 4>> events; for (int i = 1; i <= N; ++i) { int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2; events.push_back({x1, y1, y2 + 1, i}); events.push_back({x2 + 1, y1, y2 + 1, i + MX}); } sort(events.begin(), events.end(), [&](auto& a, auto& b) { if (a[0] == b[0]) { if ((a[3] >= MX) ^ (b[3] >= MX)) return a[3] >= MX; else return a[1] < b[1]; } return a[0] < b[0]; }); for (auto& i : events) if (i[3] > MX) i[3] -= MX; vector<array<int, 3>> shots(M); for (auto& [x, y, c] : shots) cin >> x >> y >> c; sort(shots.begin(), shots.end()); // y1, y2, index // [y1, y2) set<array<int, 3>> s; s.insert({0, (int)2E9, 0}); int l = 0; for (auto& [x, y, c] : shots) { for (; l < 2 * N && events[l][0] <= x; ++l) { array<int, 3> v = {{events[l][1], events[l][2], events[l][3]}}; // y1, y2, index if (s.find(v) != s.end()) erase(s, v); else add(s, v); } int prev = (*s.begin())[0]; for (auto& i : s) { assert(i[0] == prev); prev = i[1]; } auto it = s.upper_bound({y + 1, 0, 0}); --it; // cout << "it: " << (*it)[2] << endl << endl; cols[(*it)[2]].insert(c); } for (int i = 1; i <= N; ++i) dfs(i); for (int i = 1; i <= N; ++i) cout << totalColours[i] << '\n'; return 0; } /*****************************= -+**********************************= :-*****************************************+: ..:*************+=+*******************************=. ..-==*****************+=-+*****************************+. ..-=***********************+--+****************************= :+**************#*#**********+--+***************************- .=--=. .+*********************#*********+--****************************++++----: -+***********************##*********--+********************************+--=. =****=**********************#*********+-=***************************#*****+--= .=****+***********************************-=*********************#*****##*****=-=. :=*****=************************************=-*****************#******#####*****=-=. .=**+***=**************************#**********==***********##*******#**######*****+-=. +***=***+***************************#**********-+*****####********#*****#####******+-=: =+**=****+****************#**********************-*####*********##***#*#######*******+-=. .=*#*=****=****************#***********#**********++#*********###****#*#*######********+-=. =**#++****=***#******#******#***********#**********=*******####****##**#########********=-= .=*##=****#=***#*******#*****#*#*********#*#********+****#####****###**#*######%#*********-== -*###=**###+*#*#######*##*######*######**##########*#*####*....-#########%##%##%##########=-*. =*###+######+############################################=..+=-+.########%##%##%##########*-+* +###*+######**#################%##########%###########%#*..=-+===-######%###+##%###########-+#. .+###**#######+###%############%#%#########%###########%#...=*:.=:.#####%#%%#+##%###########=+#+ .-+#%#**#######%=###%#############%%######%#%%##########*...+===+...####%%%%% *%%############=+## .=*#%#*+#######%%+##%%###########%#%%%######%%#%########=...====+..####%%%%%: *%%############=*## .+*#*##+###%###%%%%##%%##########*##%%%####%%%#%#######%*=-..====:####%%%%%= #%%############=###- .+*#=#-=#####%#%%%####%%%########+*###%%%##%%%#%#######%*==:==+-.*##%%%%%%+ #%%###########*=###+ :=##=#-+####%%#%%%#**##%%%#######+++#*+%*%%%%%#%%########=.-=....##%%%%%%*....%%%#####%#####+=####- .#*.#--*#####%#%%#****##%%#####+-===#+=**+%%%#%%########=......+%%%%%%%+ %%######%#####=*####. #* *+.*####%%%%%#++++- :*%%###+.....--..*==#%%%########==-:::=%%%%%%%- %%######%#####=#####. -# .%.=####%%%%%#++=*......:##*.......-..-==%%%#####%##=#%%%%%%%%%%# #%######%####*=###%# *. +-.####%%%%%%===.=....-:.*#...........-=%%%#######*==*@%%%%%%%* #%######%####+*###%# *.:###%%%%%%-.....=......*:...........-%%%######%+*==*#%%%%%# +%######%####=####%#. =.=###%%%%%:.............:............#*%%####*#*=====%@%%% :%#####%%####+######: .=%##%%%%%*.............:............#*%%####+#+======%#%* .:-=%%%%%%%%###+#####+#- .%%##%%%-*-..............::::.......#+%%####+#=====-...#: :*%%%%%%%%%%%%%%%%###*#####=#= .####%%%:.:-.......--...............#=#%###+*#====-...:*%%%%%%%%%%%%%%%%%%%%%%########:#+ *-#%#%%- -..........:----........:*=#%##%=*+=====#%%%%%%%%%%%%%%%%%%%%%%%%%%########:#* =*.%%%%= .:........:::..........=.=####+=#=*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%###.*# #..%%%#. -....................-:+###%*%@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*# +- :%%%#+ =..................===%##%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#:. .#. =%% .*= -.............:+#%%%%#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%+. .* *%- .-........:*%%%%%%%#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@%%%%%%#. .=. ## ..-:..:#%%%%%%%%%%@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@%%%: ..=*- .*@@@@@%%%%%%%%%%%%%%%@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-. #@%%%%%%%%%%%%%%%%%%%@%%%@@@@@@@@@@@@%%%%%%%%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@@@@@@@@@@@%%%%%%%%%@@@@%%%%%@@@@@@@@@%%%%%%%%%%%%%%%%%@%%%@@@@@@@@@@@+-%* :-@@@@@@@@@%%%%%%%%%%%@@@@@%%%%@@@@@@@@@@%%%%%%%%%%%%%%%%%@@%%%@@@@@@@@@#--*% :=@@@@@@%%%%%%%%%%%@%@@@@%%%@@@@@@@@@@@@%%%%%%%%%%%%%%%%%@@%%%@@@@@@@%%---%+ -:-@@@@%%%%%%%%@%%%@@%@@@%%%@@@@@@@@@@@@@%%%%%%%%%%%%%%%%%@@@%%@@@@@%%%%=--*% -=@@@%%%%%%%%%@@%%@@%@@@@%%@@@@@@@@@@@@@@@%%%%%%%%%%%%%%%%@@@%%%@@%%%%%%+--=%+ -=@@%%%%%%%%%%@@%%@@%%@@@@%@@@@@@@@@@@@@@@@@%%%%%%%%%%%%%%%%@@@%%@##%%%%%#---*%- -+@%%%%%%%%%%%@@@%@@%%@@@@@%@@@@@@@@@@@@@@@@@%%%%%%%%%%%%%%%%@@@@%@##%%%%%%====%*/
#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...