#include <bits/stdc++.h>
using namespace std;
int n;
struct Circle{
long long x, y, r, id;
} sorted[300005], arr[300005];;
inline 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);
}
inline long long ii(long long a, long long b){
return a * (1LL << 32LL) + b;
}
long long ans[300005];
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
unordered_map<long long, vector<int>, custom_hash> GRID;
long long gridSize = 1LL << 61LL;
inline void buildGrid(long long newGridSize){
gridSize = newGridSize;
GRID.clear();
for(int i = 0;i < n;i++){
if(ans[i] == -1){
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 << 31LL); y += (1LL << 31LL);
arr[i] = {x, y, r, i};
sorted[i] = {x, y, r, i};
}
sort(sorted,sorted+n,comp);
for(int i = 0;i < n;i++){
Circle C = sorted[i];
if(ans[C.id] != -1) continue;
if(gridSize > 2 * 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++){
vector<int> &points = GRID[ii(x,y)];
for(int p = 0;p < (int) points.size();p++){
if(intersect(arr[points[p]],C)){
ans[points[p]] = C.id;
points[p] = points.back();
points.pop_back();
p--;
}
}
}
}
}
for(int i = 0;i < n;i++) cout << ans[i] + 1 << " ";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
380 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
4 ms |
376 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 |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
504 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
504 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
9 ms |
760 KB |
Output is correct |
20 |
Correct |
9 ms |
760 KB |
Output is correct |
21 |
Correct |
9 ms |
760 KB |
Output is correct |
22 |
Correct |
33 ms |
5768 KB |
Output is correct |
23 |
Correct |
32 ms |
5768 KB |
Output is correct |
24 |
Correct |
32 ms |
5768 KB |
Output is correct |
25 |
Correct |
31 ms |
5892 KB |
Output is correct |
26 |
Correct |
32 ms |
5896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
230 ms |
24148 KB |
Output is correct |
2 |
Correct |
220 ms |
23812 KB |
Output is correct |
3 |
Correct |
227 ms |
24996 KB |
Output is correct |
4 |
Correct |
232 ms |
23868 KB |
Output is correct |
5 |
Correct |
273 ms |
27524 KB |
Output is correct |
6 |
Correct |
1427 ms |
90872 KB |
Output is correct |
7 |
Correct |
332 ms |
32008 KB |
Output is correct |
8 |
Correct |
488 ms |
41404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
1575 ms |
105544 KB |
Output is correct |
3 |
Execution timed out |
3096 ms |
352516 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3089 ms |
352444 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
380 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
4 ms |
376 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 |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
504 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
504 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
9 ms |
760 KB |
Output is correct |
20 |
Correct |
9 ms |
760 KB |
Output is correct |
21 |
Correct |
9 ms |
760 KB |
Output is correct |
22 |
Correct |
33 ms |
5768 KB |
Output is correct |
23 |
Correct |
32 ms |
5768 KB |
Output is correct |
24 |
Correct |
32 ms |
5768 KB |
Output is correct |
25 |
Correct |
31 ms |
5892 KB |
Output is correct |
26 |
Correct |
32 ms |
5896 KB |
Output is correct |
27 |
Correct |
16 ms |
1144 KB |
Output is correct |
28 |
Correct |
12 ms |
1144 KB |
Output is correct |
29 |
Correct |
12 ms |
1144 KB |
Output is correct |
30 |
Correct |
81 ms |
11320 KB |
Output is correct |
31 |
Correct |
84 ms |
11196 KB |
Output is correct |
32 |
Correct |
91 ms |
11324 KB |
Output is correct |
33 |
Correct |
84 ms |
8564 KB |
Output is correct |
34 |
Correct |
83 ms |
8600 KB |
Output is correct |
35 |
Correct |
85 ms |
8192 KB |
Output is correct |
36 |
Correct |
1493 ms |
107304 KB |
Output is correct |
37 |
Correct |
1498 ms |
106820 KB |
Output is correct |
38 |
Correct |
1555 ms |
106832 KB |
Output is correct |
39 |
Correct |
479 ms |
33936 KB |
Output is correct |
40 |
Correct |
475 ms |
34016 KB |
Output is correct |
41 |
Correct |
472 ms |
33916 KB |
Output is correct |
42 |
Correct |
191 ms |
18568 KB |
Output is correct |
43 |
Correct |
1847 ms |
176452 KB |
Output is correct |
44 |
Correct |
1802 ms |
176868 KB |
Output is correct |
45 |
Correct |
1843 ms |
176620 KB |
Output is correct |
46 |
Correct |
1831 ms |
176884 KB |
Output is correct |
47 |
Correct |
1779 ms |
176964 KB |
Output is correct |
48 |
Correct |
1769 ms |
176972 KB |
Output is correct |
49 |
Correct |
1823 ms |
177120 KB |
Output is correct |
50 |
Correct |
1769 ms |
176964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
380 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
4 ms |
376 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 |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
504 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
504 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
9 ms |
760 KB |
Output is correct |
20 |
Correct |
9 ms |
760 KB |
Output is correct |
21 |
Correct |
9 ms |
760 KB |
Output is correct |
22 |
Correct |
33 ms |
5768 KB |
Output is correct |
23 |
Correct |
32 ms |
5768 KB |
Output is correct |
24 |
Correct |
32 ms |
5768 KB |
Output is correct |
25 |
Correct |
31 ms |
5892 KB |
Output is correct |
26 |
Correct |
32 ms |
5896 KB |
Output is correct |
27 |
Correct |
230 ms |
24148 KB |
Output is correct |
28 |
Correct |
220 ms |
23812 KB |
Output is correct |
29 |
Correct |
227 ms |
24996 KB |
Output is correct |
30 |
Correct |
232 ms |
23868 KB |
Output is correct |
31 |
Correct |
273 ms |
27524 KB |
Output is correct |
32 |
Correct |
1427 ms |
90872 KB |
Output is correct |
33 |
Correct |
332 ms |
32008 KB |
Output is correct |
34 |
Correct |
488 ms |
41404 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
36 |
Correct |
1575 ms |
105544 KB |
Output is correct |
37 |
Execution timed out |
3096 ms |
352516 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |