#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) >= r[i]);
if ((1LL << step) >= 2 * r[i]) {
while ((1LL << step) >= 2 * 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 |
1 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 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
209 ms |
17380 KB |
Output is correct |
2 |
Correct |
200 ms |
17632 KB |
Output is correct |
3 |
Correct |
192 ms |
18532 KB |
Output is correct |
4 |
Incorrect |
209 ms |
16352 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
641 ms |
16496 KB |
Output is correct |
3 |
Correct |
2140 ms |
47452 KB |
Output is correct |
4 |
Correct |
2201 ms |
55088 KB |
Output is correct |
5 |
Correct |
2229 ms |
49404 KB |
Output is correct |
6 |
Correct |
751 ms |
24936 KB |
Output is correct |
7 |
Correct |
282 ms |
13296 KB |
Output is correct |
8 |
Correct |
37 ms |
3064 KB |
Output is correct |
9 |
Correct |
2600 ms |
53884 KB |
Output is correct |
10 |
Correct |
1868 ms |
46728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1768 ms |
47476 KB |
Output is correct |
2 |
Correct |
1209 ms |
54012 KB |
Output is correct |
3 |
Correct |
682 ms |
31968 KB |
Output is correct |
4 |
Correct |
1272 ms |
54404 KB |
Output is correct |
5 |
Correct |
1407 ms |
54752 KB |
Output is correct |
6 |
Correct |
295 ms |
27232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 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 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 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 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |