#include <bits/stdc++.h>
using ll = long long;
#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;
ll sq(int t) {
return (ll)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);
});
build();
for (int i : desc) {
if (a[i] != -1) {
continue;
}
assert((1LL << step) >= r[i]);
if ((1LL << step) >= 2 * r[i]) {
while ((1LL << step) >= 2 * r[i]) {
--step;
}
build();
}
int delta = 1LL << step;
int k = (step == 30 ? 1 : 2);
for (int dx = -k * delta; dx <= +k * delta; dx += delta) {
for (int dy = -k * delta; dy <= +k * 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 |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Execution timed out |
3076 ms |
384 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
189 ms |
9536 KB |
Output is correct |
2 |
Correct |
190 ms |
14668 KB |
Output is correct |
3 |
Correct |
192 ms |
15484 KB |
Output is correct |
4 |
Execution timed out |
3072 ms |
13464 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
583 ms |
15124 KB |
Output is correct |
3 |
Correct |
2244 ms |
42036 KB |
Output is correct |
4 |
Correct |
2543 ms |
47820 KB |
Output is correct |
5 |
Correct |
2432 ms |
42436 KB |
Output is correct |
6 |
Correct |
920 ms |
21880 KB |
Output is correct |
7 |
Correct |
293 ms |
11848 KB |
Output is correct |
8 |
Correct |
37 ms |
2688 KB |
Output is correct |
9 |
Execution timed out |
3047 ms |
46788 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1917 ms |
42088 KB |
Output is correct |
2 |
Correct |
1255 ms |
47956 KB |
Output is correct |
3 |
Correct |
516 ms |
22676 KB |
Output is correct |
4 |
Correct |
1283 ms |
47912 KB |
Output is correct |
5 |
Correct |
1424 ms |
47896 KB |
Output is correct |
6 |
Correct |
287 ms |
17524 KB |
Output is correct |
# |
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 |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Execution timed out |
3076 ms |
384 KB |
Time limit exceeded |
7 |
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 |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Execution timed out |
3076 ms |
384 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |