#include <bits/stdc++.h>
using namespace std;
using pii = pair <int, int>;
const int maxn = 300005;
struct data {
int x, y, r, idx;
bool operator < (data p) const {
return make_pair(r, -idx) > make_pair(p.r, -p.idx);
}
} a[maxn];
int c[maxn];
int main() {
ios_base :: sync_with_stdio (false);
cin.tie(0);
int n;
cin >> n;
set <data> s;
const int shift = 1000000007;
for(int i = 1; i <= n; i++) {
cin >> a[i].x >> a[i].y >> a[i].r;
a[i].idx = i;
a[i].x += shift; a[i].y += shift;
s.insert(a[i]);
}
map <pii, vector <int>> cont;
int block = INT_MAX;
function <void(int)> rebuild = [&] (int bs) {
block = bs;
cont.clear();
for(auto i : s) {
cont[pii(i.x / block, i.y / block)].push_back(i.idx);
}
};
function <bool(int, int)> reach = [&] (int i, int j) {
auto square = [] (long long x) { return x * x; };
return square(a[i].x - a[j].x) + square(a[i].y - a[j].y) <= square(a[i].r + a[j].r);
};
rebuild(s.begin() -> r * 2);
while(!s.empty()) {
if(4LL * s.begin() -> r < block) {
rebuild(s.begin() -> r * 2);
}
data d = *s.begin();
int bx = d.x / block;
int by = d.y / block;
for(int i : {-1, 0, 1}) {
for(int j : {-1, 0, 1}) {
int dx = bx + i;
int dy = by + j;
for(auto k : cont[pii(dx, dy)]) {
if(reach(k, d.idx)) {
s.erase(a[k]);
c[k] = d.idx;
}
}
}
}
}
for(int i = 1; i <= n; i++) {
cout << c[i] << " \n"[i == n];
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
488 ms |
27404 KB |
Output is correct |
2 |
Incorrect |
483 ms |
27324 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
736 ms |
51552 KB |
Output is correct |
3 |
Correct |
2853 ms |
155764 KB |
Output is correct |
4 |
Correct |
2740 ms |
156236 KB |
Output is correct |
5 |
Correct |
2518 ms |
98284 KB |
Output is correct |
6 |
Correct |
936 ms |
49864 KB |
Output is correct |
7 |
Correct |
402 ms |
25208 KB |
Output is correct |
8 |
Correct |
49 ms |
6780 KB |
Output is correct |
9 |
Execution timed out |
3099 ms |
116984 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2215 ms |
228960 KB |
Output is correct |
2 |
Correct |
1758 ms |
236172 KB |
Output is correct |
3 |
Incorrect |
828 ms |
39928 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |