Submission #1228537

#TimeUsernameProblemLanguageResultExecution timeMemory
1228537kfhjadPlahte (COCI17_plahte)C++20
0 / 160
90 ms18600 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; // sweep line up to each shot coordinate // const int MX = 80005; 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(); } void add(auto& s, auto& v) { auto it = s.lower_bound(v); --it; array<int, 3> temp = *it; if (temp[2] != -1) adj[temp[2]].push_back(v[2]); s.erase(it); int yTemp = temp[1]; temp[1] = v[0] - 1; s.insert(temp); s.insert(v); temp[1] = yTemp; temp[0] = v[1] + 1; s.insert(temp); } void erase(auto& s, auto& v) { auto it = s.find(v); --it; array<int, 3> temp = *it; it = s.erase(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 vector<array<int, 4>> events; for (int i = 0; i < N; ++i) { int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2; events.push_back({x1, y1, y2, i}); events.push_back({x2 + 1, y1, y2, i + N}); } sort(events.begin(), events.end(), [&](auto& a, auto& b) { if (a[0] == b[0]) { if ((a[3] >= N) ^ (b[3] >= N)) return a[3] >= N; else return a[1] < b[1]; } return a[0] < b[0]; }); // for (auto& i : events) // if (i[3] >= N) i[3] -= N; // sort(events.begin(), events.end()); vector<array<int, 3>> shots(M); for (auto& [x, y, c] : shots) cin >> x >> y >> c; sort(shots.begin(), shots.end()); // y1, y2, index set<array<int, 3>> s; s.insert({0, (int)1E9 + 1, -1}); int l = 0; for (auto& [x, y, c] : shots) { bool flag = false; for (; l < 2 * N && events[l][0] <= x; ++l) { array<int, 3> v = {events[l][1], events[l][2], events[l][3]}; if (flag && v[2] >= N) assert(false); if (v[2] < N) flag = true; if (v[2] >= N) v[2] -= N; if (s.find(v) != s.end()) erase(s, v); else add(s, v); // for (auto& i : s) // cout << i[0] << ' ' << i[1] << ' ' << i[2] << endl; // cout << endl; } auto it = s.upper_bound({y, (int)1E9 + 5, 0}); if (it == s.begin()) continue; --it; // cout << "it: " << (*it)[2] << endl; if ((*it)[2] != -1) cols[(*it)[2]].insert(c); } for (int i = 0; i < N; ++i) dfs(i); for (int i = 0; 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...