Submission #966744

#TimeUsernameProblemLanguageResultExecution timeMemory
966744Soumya1Circle selection (APIO18_circle_selection)C++17
100 / 100
1018 ms36944 KiB
#include <bits/stdc++.h> using namespace std; const int mxN = 3e5 + 5; int x[mxN], y[mxN], r[mxN], ans[mxN]; bool intersect(int a, int b) { return 1LL * (x[a] - x[b]) * (x[a] - x[b]) + 1LL * (y[a] - y[b]) * (y[a] - y[b]) <= 1LL * (r[a] + r[b]) * (r[a] + r[b]); } int block; vector<int> all[mxN]; vector<pair<int, int>> vv; int n; int get(pair<int, int> p) { auto it = lower_bound(vv.begin(), vv.end(), p); if (it != vv.end() && *it == p) return it - vv.begin(); return -1; } void scale() { vv.clear(); for (int i = 0; i < n; i++) all[i].clear(); for (int i = 0; i < n; i++) { if (ans[i]) continue; vv.push_back({x[i] / block, y[i] / block}); } sort(vv.begin(), vv.end()); vv.erase(unique(vv.begin(), vv.end()), vv.end()); for (int i = 0; i < n; i++) { if (ans[i]) continue; all[get({x[i] / block, y[i] / block})].push_back(i); } } void testCase() { cin >> n; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i] >> r[i]; } vector<int> ord(n); iota(ord.begin(), ord.end(), 0); sort(ord.begin(), ord.end(), [&](int i, int j) { if (r[i] != r[j]) return r[i] > r[j]; return i < j; }); block = r[ord[0]]; scale(); for (int i : ord) { if (ans[i]) continue; if (2 * r[i] < block) { block = r[i]; scale(); } for (int xx = x[i] / block - 2; xx <= x[i] / block + 2; xx++) { for (int yy = y[i] / block - 2; yy <= y[i] / block + 2; yy++) { auto id = get({xx, yy}); if (id == -1) continue; for (int j = 0; j < all[id].size(); ) { if (intersect(i, all[id][j])) { ans[all[id][j]] = i + 1; swap(all[id][j], all[id].back()); all[id].pop_back(); } else { j++; } } } } } for (int i = 0; i < n; i++) cout << ans[i] << " "; cout << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); testCase(); return 0; }

Compilation message (stderr)

circle_selection.cpp: In function 'void testCase()':
circle_selection.cpp:54:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for (int j = 0; j < all[id].size(); ) {
      |                         ~~^~~~~~~~~~~~~~~~
#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...