#include <bits/stdc++.h>
using ll = long long;
#define int ll
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define mp make_pair
#define mt make_tuple
using namespace std;
const int N = 3e5 + 5;
int n;
int x[N];
int y[N];
int r[N];
int a[N];
int step = 30;
vector<int> desc;
int sq(int t) {
return t * t;
}
bool cross(int i, int j) {
return sq(x[i] - x[j]) + sq(y[i] - y[j]) <= sq(r[i] + r[j]);
}
pair<int, int> id(int xi, int yi) {
return {(xi >> step), (yi >> step)};
}
map<pair<int, int>, vector<int>> table;
void build() {
table.clear();
for (int i = 0; i < n; ++i) {
if (a[i] == -1) {
table[id(x[i], y[i])].push_back(i);
}
}
}
signed main() {
#ifdef LC
assert(freopen("input.txt", "r", stdin));
#endif // LC
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> x[i] >> y[i] >> r[i];
a[i] = -1;
desc.push_back(i);
}
sort(all(desc), [&](int i, int j) {
return mp(-r[i], i) < mp(-r[j], j);
});
for (int i : desc) {
if (a[i] != -1) {
continue;
}
assert((1LL << step) >= 2 * r[i]);
while ((1LL << step) >= 4 * r[i]) {
--step;
build();
}
int delta = 1LL << step;
for (int dx = -2 * delta; dx <= +2 * delta; dx += delta) {
for (int dy = -2 * delta; dy <= +2 * delta; dy += delta) {
pair<int, int> v = id(x[i] + dx, y[i] + dy);
if (!table.count(v)) {
continue;
}
vector<int> tmp;
for (int j : table[v]) {
if (cross(i, j)) {
assert(a[j] == -1);
a[j] = i;
} else {
tmp.push_back(j);
}
}
table[v] = tmp;
}
}
}
for (int i = 0; i < n; ++i) {
cout << a[i] + 1 << " ";
}
cout << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
209 ms |
18992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1184 ms |
15828 KB |
Output is correct |
3 |
Execution timed out |
3090 ms |
45308 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3026 ms |
45544 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |