#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> ii;
int n;
struct Circle{
long long x, y, r, id;
} arr[300005];
bool intersect(Circle a, Circle b){
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) <= (a.r + b.r) * (a.r + b.r);
}
long long ans[300005];
bool used[300005];
struct pair_hash{
std::size_t operator () (ii const &pair) const{
return pair.first ^ pair.second;
}
};
unordered_map<ii, vector<int>, pair_hash> GRID;
long long gridSize = 1LL << 61LL;
void buildGrid(long long newGridSize){
gridSize = newGridSize;
GRID.clear();
for(int i = 0;i < n;i++){
if(!used[i]){
long long xSquare = arr[i].x / gridSize;
long long ySquare = arr[i].y / gridSize;
GRID[ii(xSquare,ySquare)].push_back(i);
}
}
}
bool comp(Circle a, Circle b){
if(a.r == b.r) return a.id < b.id;
else return a.r > b.r;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
fill(ans, ans + n, -1);
for(int i = 0;i < n;i++){
long long x, y, r; cin >> x >> y >> r;
x += (1LL << 30LL); y += (1LL << 30LL);
arr[i] = {x, y, r, i};
}
sort(arr,arr+n,comp);
for(int i = 0;i < n;i++){
Circle C = arr[i];
if(used[i]) continue;
if(gridSize > 2LL * C.r){
buildGrid(C.r);
}
long long xSquare = C.x / gridSize;
long long ySquare = C.y / gridSize;
for(long long x = xSquare - 2;x <= xSquare + 2;x++){
for(long long y = ySquare - 2;y <= ySquare + 2;y++){
if(GRID.find(ii(x,y)) == GRID.end()) continue;
vector<int> &points = GRID[ii(x,y)];
for(int p = 0;p < (int) points.size();p++){
if(intersect(arr[points[p]], C)){
ans[arr[points[p]].id] = C.id;
used[points[p]] = true;
points[p] = points.back();
points.pop_back();
p--;
}
}
}
}
}
for(int i = 0;i < n;i++) cout << ans[i] + 1 << " ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
380 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
380 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
420 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
380 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
6 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
376 KB |
Output is correct |
18 |
Correct |
6 ms |
504 KB |
Output is correct |
19 |
Correct |
8 ms |
888 KB |
Output is correct |
20 |
Correct |
8 ms |
760 KB |
Output is correct |
21 |
Correct |
8 ms |
760 KB |
Output is correct |
22 |
Correct |
12 ms |
1272 KB |
Output is correct |
23 |
Correct |
12 ms |
1272 KB |
Output is correct |
24 |
Correct |
13 ms |
1272 KB |
Output is correct |
25 |
Correct |
13 ms |
1404 KB |
Output is correct |
26 |
Correct |
13 ms |
1272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
208 ms |
14632 KB |
Output is correct |
2 |
Correct |
209 ms |
14764 KB |
Output is correct |
3 |
Correct |
207 ms |
15560 KB |
Output is correct |
4 |
Correct |
209 ms |
15268 KB |
Output is correct |
5 |
Correct |
251 ms |
15256 KB |
Output is correct |
6 |
Correct |
516 ms |
30132 KB |
Output is correct |
7 |
Correct |
272 ms |
17552 KB |
Output is correct |
8 |
Correct |
313 ms |
20644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
901 ms |
15240 KB |
Output is correct |
3 |
Execution timed out |
3051 ms |
52232 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1243 ms |
46216 KB |
Output is correct |
2 |
Correct |
920 ms |
53256 KB |
Output is correct |
3 |
Execution timed out |
3017 ms |
30600 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
380 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
380 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
420 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
380 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
6 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
376 KB |
Output is correct |
18 |
Correct |
6 ms |
504 KB |
Output is correct |
19 |
Correct |
8 ms |
888 KB |
Output is correct |
20 |
Correct |
8 ms |
760 KB |
Output is correct |
21 |
Correct |
8 ms |
760 KB |
Output is correct |
22 |
Correct |
12 ms |
1272 KB |
Output is correct |
23 |
Correct |
12 ms |
1272 KB |
Output is correct |
24 |
Correct |
13 ms |
1272 KB |
Output is correct |
25 |
Correct |
13 ms |
1404 KB |
Output is correct |
26 |
Correct |
13 ms |
1272 KB |
Output is correct |
27 |
Correct |
12 ms |
1272 KB |
Output is correct |
28 |
Correct |
12 ms |
1272 KB |
Output is correct |
29 |
Correct |
13 ms |
1144 KB |
Output is correct |
30 |
Correct |
22 ms |
2168 KB |
Output is correct |
31 |
Correct |
23 ms |
2168 KB |
Output is correct |
32 |
Correct |
21 ms |
2168 KB |
Output is correct |
33 |
Correct |
82 ms |
8564 KB |
Output is correct |
34 |
Correct |
85 ms |
8624 KB |
Output is correct |
35 |
Correct |
83 ms |
8044 KB |
Output is correct |
36 |
Correct |
309 ms |
17800 KB |
Output is correct |
37 |
Correct |
268 ms |
18052 KB |
Output is correct |
38 |
Correct |
382 ms |
17928 KB |
Output is correct |
39 |
Execution timed out |
3063 ms |
14508 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
380 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
380 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
420 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
380 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
6 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
376 KB |
Output is correct |
18 |
Correct |
6 ms |
504 KB |
Output is correct |
19 |
Correct |
8 ms |
888 KB |
Output is correct |
20 |
Correct |
8 ms |
760 KB |
Output is correct |
21 |
Correct |
8 ms |
760 KB |
Output is correct |
22 |
Correct |
12 ms |
1272 KB |
Output is correct |
23 |
Correct |
12 ms |
1272 KB |
Output is correct |
24 |
Correct |
13 ms |
1272 KB |
Output is correct |
25 |
Correct |
13 ms |
1404 KB |
Output is correct |
26 |
Correct |
13 ms |
1272 KB |
Output is correct |
27 |
Correct |
208 ms |
14632 KB |
Output is correct |
28 |
Correct |
209 ms |
14764 KB |
Output is correct |
29 |
Correct |
207 ms |
15560 KB |
Output is correct |
30 |
Correct |
209 ms |
15268 KB |
Output is correct |
31 |
Correct |
251 ms |
15256 KB |
Output is correct |
32 |
Correct |
516 ms |
30132 KB |
Output is correct |
33 |
Correct |
272 ms |
17552 KB |
Output is correct |
34 |
Correct |
313 ms |
20644 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
36 |
Correct |
901 ms |
15240 KB |
Output is correct |
37 |
Execution timed out |
3051 ms |
52232 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |