#include <bits/stdc++.h>
using namespace std;
#define v vector
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
struct Circle{
ll x, y, r, i;
};
int N;
v<Circle> C;
bool compC(Circle& a, Circle& b){
if(a.r==b.r) return a.i<b.i;
return a.r>b.r;
}
bool isect(Circle& a, Circle& b){
ll dx=a.x-b.x;
ll dy=a.y-b.y;
ll r=a.r+b.r;
return dx*dx+dy*dy <= r*r;
}
v<ll> eBy;
void sub1(){
for(int i=0; i<N; i++){
if(eBy[C[i].i]!=-1) continue;
eBy[C[i].i] = C[i].i;
for(int j=i+1; j<N; j++){
if(eBy[C[j].i]==-1 && isect(C[i], C[j])){
eBy[C[j].i] = C[i].i;
}
}
}
}
void sub2(){
set<ii> pts;
for(int i=0; i<N; i++){
pts.insert(make_pair(C[i].x-C[i].r, i));
pts.insert(make_pair(C[i].x+C[i].r, i));
}
for(int i=0; i<N; i++){
if(eBy[C[i].i]!=-1) continue;
v<int> del;
auto it = pts.lower_bound(make_pair(C[i].x-C[i].r, -1));
while(it!=pts.end() && (*it).fi<=C[i].x+C[i].r){
del.push_back((*it).se);
it++;
}
for(int ind:del){
eBy[C[ind].i] = C[i].i;
pts.erase(make_pair(C[ind].x-C[ind].r, ind));
pts.erase(make_pair(C[ind].x+C[ind].r, ind));
}
}
}
void sub3(){
set<ii> xs;
set<ii> ys;
for(int i=0; i<N; i++){
ys.insert({C[i].y-C[i].r, i});
ys.insert({C[i].y+C[i].r, i});
eBy[i] = i;
}
for(ii y:ys){
ll x = C[y.se].x;
if(C[y.se].y+C[y.se].r==y.fi) xs.erase({x,y.se});
auto it = xs.lower_bound({x,-1});
if(it!=xs.end()){
ll ind = (*it).se;
if(isect(C[y.se], C[ind])){
ll e = (compC(C[y.se], C[ind]) ? y.se : ind);
eBy[C[y.se].i] = C[e].i;
eBy[C[ind].i] = C[e].i;
}
}
if(it!=xs.begin()){
it--;
ll ind = (*it).se;
if(isect(C[y.se], C[ind])){
ll e = (compC(C[y.se], C[ind]) ? y.se : ind);
eBy[C[y.se].i] = C[e].i;
eBy[C[ind].i] = C[e].i;
}
}
if(C[y.se].y-C[y.se].r == y.fi) xs.insert({x,y.se});
}
}
void sub4(){
map<ii, v<ll>> grid;
for(int i=0; i<N; i++){
C[i].x+=1e9;
C[i].y+=1e9;
grid[{C[i].x/C[i].r, C[i].y/C[i].r}].push_back(i);
}
for(int i=0; i<N; i++){
Circle& cur = C[i];
if(eBy[cur.i]!=-1) continue;
for(ll x=cur.x/cur.r - 2; x<=cur.x/cur.r+2; x++){
for(ll y=cur.y/cur.r-2; y<=cur.y/cur.r+2; y++){
if(grid.find({x,y})==grid.end()) continue;
for(ll c:grid[{x,y}]){
if(eBy[C[c].i]==-1 && isect(C[c],cur)) eBy[C[c].i] = cur.i;
}
}
}
}
}
void full(){
map<ii, v<ll>> grid;
for(int i=0; i<N; i++){
C[i].x+=1e9;
C[i].y+=1e9;
}
for(ll ri = 30; ri>=0; ri--){
ll r = (1<<ri);
grid.clear();
for(int i=0; i<N; i++){
if(eBy[C[i].i]!=-1) continue;
grid[{C[i].x/r, C[i].y/r}].push_back(i);
}
for(int i=0; i<N; i++){
Circle& cur = C[i];
if(cur.r<r/2) break;
if(eBy[cur.i]!=-1 || cur.r>r) continue;
for(ll x=cur.x/r - 2; x<=cur.x/r+2; x++){
for(ll y=cur.y/r-2; y<=cur.y/r+2; y++){
if(grid.find({x,y})==grid.end()) continue;
for(ll c:grid[{x,y}]){
if(eBy[C[c].i]==-1 && isect(C[c],cur)) eBy[C[c].i] = cur.i;
}
}
}
}
}
}
int main(){
cin>>N;
bool s2 = true;
bool s4 = true;
for(int i=0; i<N; i++){
ll x,y,r;
cin>>x>>y>>r;
C.push_back({x,y,r,i});
s2 = s2 && y==0;
s4 = s4 && r==C[0].r;
}
sort(C.begin(), C.end(), compC);
eBy = v<ll>(N,-1);
if(s4) sub4();
else full();
// if(N<=5000) sub1();
// else if(s2) sub2();
// else if(s4) sub4();
// else sub3();
for(int i:eBy) cout<<i+1<<" ";
cout<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
6 ms |
728 KB |
Output is correct |
20 |
Correct |
6 ms |
800 KB |
Output is correct |
21 |
Correct |
6 ms |
728 KB |
Output is correct |
22 |
Correct |
21 ms |
1216 KB |
Output is correct |
23 |
Correct |
23 ms |
1240 KB |
Output is correct |
24 |
Correct |
21 ms |
1236 KB |
Output is correct |
25 |
Correct |
23 ms |
1240 KB |
Output is correct |
26 |
Correct |
22 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
296 ms |
17812 KB |
Output is correct |
2 |
Correct |
289 ms |
18836 KB |
Output is correct |
3 |
Correct |
291 ms |
19968 KB |
Output is correct |
4 |
Correct |
282 ms |
18812 KB |
Output is correct |
5 |
Correct |
504 ms |
20496 KB |
Output is correct |
6 |
Correct |
1043 ms |
28312 KB |
Output is correct |
7 |
Correct |
491 ms |
20420 KB |
Output is correct |
8 |
Correct |
628 ms |
21952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
594 ms |
16000 KB |
Output is correct |
3 |
Correct |
2723 ms |
47328 KB |
Output is correct |
4 |
Correct |
2655 ms |
47348 KB |
Output is correct |
5 |
Correct |
1900 ms |
41548 KB |
Output is correct |
6 |
Correct |
778 ms |
20652 KB |
Output is correct |
7 |
Correct |
373 ms |
11192 KB |
Output is correct |
8 |
Correct |
67 ms |
2504 KB |
Output is correct |
9 |
Correct |
2413 ms |
46180 KB |
Output is correct |
10 |
Correct |
1668 ms |
38752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1167 ms |
47004 KB |
Output is correct |
2 |
Correct |
892 ms |
46996 KB |
Output is correct |
3 |
Correct |
471 ms |
32412 KB |
Output is correct |
4 |
Correct |
945 ms |
52820 KB |
Output is correct |
5 |
Correct |
942 ms |
52988 KB |
Output is correct |
6 |
Correct |
338 ms |
26268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
6 ms |
728 KB |
Output is correct |
20 |
Correct |
6 ms |
800 KB |
Output is correct |
21 |
Correct |
6 ms |
728 KB |
Output is correct |
22 |
Correct |
21 ms |
1216 KB |
Output is correct |
23 |
Correct |
23 ms |
1240 KB |
Output is correct |
24 |
Correct |
21 ms |
1236 KB |
Output is correct |
25 |
Correct |
23 ms |
1240 KB |
Output is correct |
26 |
Correct |
22 ms |
1236 KB |
Output is correct |
27 |
Correct |
11 ms |
984 KB |
Output is correct |
28 |
Correct |
10 ms |
984 KB |
Output is correct |
29 |
Correct |
10 ms |
1048 KB |
Output is correct |
30 |
Correct |
47 ms |
1908 KB |
Output is correct |
31 |
Correct |
44 ms |
2004 KB |
Output is correct |
32 |
Correct |
48 ms |
2004 KB |
Output is correct |
33 |
Correct |
108 ms |
6584 KB |
Output is correct |
34 |
Correct |
113 ms |
6688 KB |
Output is correct |
35 |
Correct |
108 ms |
6472 KB |
Output is correct |
36 |
Correct |
695 ms |
16176 KB |
Output is correct |
37 |
Correct |
730 ms |
16188 KB |
Output is correct |
38 |
Correct |
645 ms |
16056 KB |
Output is correct |
39 |
Correct |
353 ms |
11348 KB |
Output is correct |
40 |
Correct |
345 ms |
11108 KB |
Output is correct |
41 |
Correct |
360 ms |
11448 KB |
Output is correct |
42 |
Correct |
216 ms |
15708 KB |
Output is correct |
43 |
Correct |
264 ms |
15540 KB |
Output is correct |
44 |
Correct |
265 ms |
15540 KB |
Output is correct |
45 |
Correct |
251 ms |
15456 KB |
Output is correct |
46 |
Correct |
263 ms |
15620 KB |
Output is correct |
47 |
Correct |
249 ms |
15556 KB |
Output is correct |
48 |
Correct |
268 ms |
15544 KB |
Output is correct |
49 |
Correct |
261 ms |
15544 KB |
Output is correct |
50 |
Correct |
252 ms |
15640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
6 ms |
728 KB |
Output is correct |
20 |
Correct |
6 ms |
800 KB |
Output is correct |
21 |
Correct |
6 ms |
728 KB |
Output is correct |
22 |
Correct |
21 ms |
1216 KB |
Output is correct |
23 |
Correct |
23 ms |
1240 KB |
Output is correct |
24 |
Correct |
21 ms |
1236 KB |
Output is correct |
25 |
Correct |
23 ms |
1240 KB |
Output is correct |
26 |
Correct |
22 ms |
1236 KB |
Output is correct |
27 |
Correct |
296 ms |
17812 KB |
Output is correct |
28 |
Correct |
289 ms |
18836 KB |
Output is correct |
29 |
Correct |
291 ms |
19968 KB |
Output is correct |
30 |
Correct |
282 ms |
18812 KB |
Output is correct |
31 |
Correct |
504 ms |
20496 KB |
Output is correct |
32 |
Correct |
1043 ms |
28312 KB |
Output is correct |
33 |
Correct |
491 ms |
20420 KB |
Output is correct |
34 |
Correct |
628 ms |
21952 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
594 ms |
16000 KB |
Output is correct |
37 |
Correct |
2723 ms |
47328 KB |
Output is correct |
38 |
Correct |
2655 ms |
47348 KB |
Output is correct |
39 |
Correct |
1900 ms |
41548 KB |
Output is correct |
40 |
Correct |
778 ms |
20652 KB |
Output is correct |
41 |
Correct |
373 ms |
11192 KB |
Output is correct |
42 |
Correct |
67 ms |
2504 KB |
Output is correct |
43 |
Correct |
2413 ms |
46180 KB |
Output is correct |
44 |
Correct |
1668 ms |
38752 KB |
Output is correct |
45 |
Correct |
1167 ms |
47004 KB |
Output is correct |
46 |
Correct |
892 ms |
46996 KB |
Output is correct |
47 |
Correct |
471 ms |
32412 KB |
Output is correct |
48 |
Correct |
945 ms |
52820 KB |
Output is correct |
49 |
Correct |
942 ms |
52988 KB |
Output is correct |
50 |
Correct |
338 ms |
26268 KB |
Output is correct |
51 |
Correct |
11 ms |
984 KB |
Output is correct |
52 |
Correct |
10 ms |
984 KB |
Output is correct |
53 |
Correct |
10 ms |
1048 KB |
Output is correct |
54 |
Correct |
47 ms |
1908 KB |
Output is correct |
55 |
Correct |
44 ms |
2004 KB |
Output is correct |
56 |
Correct |
48 ms |
2004 KB |
Output is correct |
57 |
Correct |
108 ms |
6584 KB |
Output is correct |
58 |
Correct |
113 ms |
6688 KB |
Output is correct |
59 |
Correct |
108 ms |
6472 KB |
Output is correct |
60 |
Correct |
695 ms |
16176 KB |
Output is correct |
61 |
Correct |
730 ms |
16188 KB |
Output is correct |
62 |
Correct |
645 ms |
16056 KB |
Output is correct |
63 |
Correct |
353 ms |
11348 KB |
Output is correct |
64 |
Correct |
345 ms |
11108 KB |
Output is correct |
65 |
Correct |
360 ms |
11448 KB |
Output is correct |
66 |
Correct |
216 ms |
15708 KB |
Output is correct |
67 |
Correct |
264 ms |
15540 KB |
Output is correct |
68 |
Correct |
265 ms |
15540 KB |
Output is correct |
69 |
Correct |
251 ms |
15456 KB |
Output is correct |
70 |
Correct |
263 ms |
15620 KB |
Output is correct |
71 |
Correct |
249 ms |
15556 KB |
Output is correct |
72 |
Correct |
268 ms |
15544 KB |
Output is correct |
73 |
Correct |
261 ms |
15544 KB |
Output is correct |
74 |
Correct |
252 ms |
15640 KB |
Output is correct |
75 |
Correct |
367 ms |
29488 KB |
Output is correct |
76 |
Correct |
344 ms |
29332 KB |
Output is correct |
77 |
Correct |
347 ms |
26776 KB |
Output is correct |
78 |
Correct |
343 ms |
29180 KB |
Output is correct |
79 |
Correct |
376 ms |
28820 KB |
Output is correct |
80 |
Correct |
353 ms |
29176 KB |
Output is correct |
81 |
Correct |
2849 ms |
55524 KB |
Output is correct |
82 |
Correct |
2622 ms |
55444 KB |
Output is correct |
83 |
Correct |
2587 ms |
55444 KB |
Output is correct |
84 |
Correct |
2434 ms |
55704 KB |
Output is correct |
85 |
Correct |
2772 ms |
55348 KB |
Output is correct |
86 |
Correct |
2637 ms |
55384 KB |
Output is correct |
87 |
Correct |
2502 ms |
55140 KB |
Output is correct |
88 |
Correct |
1333 ms |
36604 KB |
Output is correct |
89 |
Correct |
1383 ms |
36504 KB |
Output is correct |
90 |
Correct |
1448 ms |
36460 KB |
Output is correct |
91 |
Correct |
1433 ms |
36344 KB |
Output is correct |
92 |
Correct |
1379 ms |
36432 KB |
Output is correct |
93 |
Correct |
2763 ms |
54420 KB |
Output is correct |
94 |
Correct |
2877 ms |
54568 KB |
Output is correct |
95 |
Correct |
2776 ms |
54560 KB |
Output is correct |
96 |
Correct |
2448 ms |
54132 KB |
Output is correct |
97 |
Execution timed out |
3038 ms |
52552 KB |
Time limit exceeded |
98 |
Halted |
0 ms |
0 KB |
- |