Submission #728320

#TimeUsernameProblemLanguageResultExecution timeMemory
728320SanguineChameleonCircle selection (APIO18_circle_selection)C++17
87 / 100
3025 ms63724 KiB
#include <bits/stdc++.h> using namespace std; void just_do_it(); int main() { #ifdef KAMIRULEZ freopen("kamirulez.inp", "r", stdin); freopen("kamirulez.out", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); just_do_it(); return 0; } struct circle { int x, y, r; }; bool intersect(circle C1, circle C2) { return 1LL * (C1.r + C2.r) * (C1.r + C2.r) >= 1LL * (C1.x - C2.x) * (C1.x - C2.x) + 1LL * (C1.y - C2.y) * (C1.y - C2.y); } const int maxn = 3e5 + 20; circle C[maxn]; int res[maxn]; set<pair<int, int>> S; map<int, set<pair<int, int>>> groups; int n; int floor(int a, int b) { return (a / b) - (a % b && (a ^ b) < 0); } void build(int len) { groups.clear(); for (auto p: S) { int i = p.second; int cx = floor(C[i].x, len); int cy = floor(C[i].y, len); groups[cx].insert({cy, i}); } } void just_do_it() { cin >> n; for (int i = 1; i <= n; i++) { cin >> C[i].x >> C[i].y >> C[i].r; S.insert({-C[i].r, i}); } int len = -1; while (!S.empty()) { int cur = S.begin()->second; if (len == -1 || C[cur].r * 2 < len) { len = C[cur].r; build(len); } int cx = floor(C[cur].x, len); int cy = floor(C[cur].y, len); auto g_it = groups.lower_bound(cx - 2); while (g_it != groups.end()) { if (g_it->first > cx + 2) { break; } auto it = g_it->second.lower_bound({cy - 2, -1}); while (it != g_it->second.end()) { if (it->first > cy + 2) { break; } int can = it->second; if (intersect(C[cur], C[can])) { res[can] = cur; it = g_it->second.erase(it); S.erase({-C[can].r, can}); } else { it++; } } g_it++; } } for (int i = 1; i <= n; i++) { cout << res[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...
#Verdict Execution timeMemoryGrader output
Fetching results...