Submission #1209021

#TimeUsernameProblemLanguageResultExecution timeMemory
1209021k1r1t0원 고르기 (APIO18_circle_selection)C++20
49 / 100
3112 ms612896 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; struct pt {int x, y;}; pt operator -(pt a, pt b) {return {a.x - b.x, a.y - b.y};} pt operator +(pt a, pt b) {return {a.x + b.x, a.y + b.y};} ll lensqr(pt a) {return 1ll * a.x * a.x + 1ll * a.y * a.y;} const int K = 31; const int N = 310000; const int INF = (int)(1e9); int n, r[N], ans[N]; pt p[N]; map<pair<int, int>, vector<int>> mp[K]; bool good(int i, int j) { return lensqr(p[i] - p[j]) <= 1ll * (r[i] + r[j]) * (r[i] + r[j]); } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> p[i].x >> p[i].y >> r[i]; p[i] = p[i] + pt(INF, INF); for (int j = 0; j < K; j++) mp[j][{p[i].x >> j, p[i].y >> j}].push_back(i); } vector<int> ord(n); iota(begin(ord), end(ord), 1); sort(begin(ord), end(ord), [&](int i, int j) { return r[i] > r[j] || (r[i] == r[j] && i < j); }); for (int k : ord) { if (ans[k]) continue; int t = 0; while ((1ll << t) < r[k]) t++; int bx = p[k].x >> t; int by = p[k].y >> t; for (int dx = -2; dx <= 2; dx++) for (int dy = -2; dy <= 2; dy++) { int cx = bx + dx; int cy = by + dy; if (!mp[t].contains({cx, cy})) continue; if (mp[t][{cx, cy}].empty()) { mp[t].erase({cx, cy}); continue; } vector<int> vec; for (auto i : mp[t][{cx, cy}]) { if (ans[i]) continue; if (good(i, k)) ans[i] = k; else vec.push_back(i); } mp[t][{cx, cy}] = vec; } } for (int i = 1; i <= n; i++) cout << ans[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...