This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
map<pair<int, int>, vector<int>> mp;
int n;
void scale() {
mp.clear();
for (int i = 0; i < n; i++) {
if (ans[i]) continue;
mp[{x[i] / block, y[i] / block}].push_back(i);
}
}
void testCase() {
cin >> n;
vector<int> all;
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 = 2 * 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 &v = mp[{xx, yy}];
for (int j = 0; j < v.size(); ) {
if (intersect(i, v[j])) {
ans[v[j]] = i + 1;
swap(v[j], v.back());
v.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:41:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int j = 0; j < v.size(); ) {
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |