#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);
full();
// if(N<=5000) sub1();
// else if(s2) sub2();
// else if(s4) sub4();
// else sub3();
for(int i:eBy) cout<<i+1<<" ";
cout<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
452 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
516 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
5 ms |
860 KB |
Output is correct |
20 |
Correct |
6 ms |
860 KB |
Output is correct |
21 |
Correct |
5 ms |
856 KB |
Output is correct |
22 |
Correct |
21 ms |
1364 KB |
Output is correct |
23 |
Correct |
22 ms |
1240 KB |
Output is correct |
24 |
Correct |
21 ms |
1240 KB |
Output is correct |
25 |
Correct |
23 ms |
1240 KB |
Output is correct |
26 |
Correct |
24 ms |
1240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
287 ms |
23444 KB |
Output is correct |
2 |
Correct |
285 ms |
24252 KB |
Output is correct |
3 |
Correct |
299 ms |
25804 KB |
Output is correct |
4 |
Correct |
302 ms |
24472 KB |
Output is correct |
5 |
Correct |
452 ms |
24212 KB |
Output is correct |
6 |
Correct |
1045 ms |
32020 KB |
Output is correct |
7 |
Correct |
500 ms |
24468 KB |
Output is correct |
8 |
Correct |
682 ms |
25748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
603 ms |
18356 KB |
Output is correct |
3 |
Correct |
2784 ms |
54024 KB |
Output is correct |
4 |
Correct |
2788 ms |
54168 KB |
Output is correct |
5 |
Correct |
1930 ms |
48156 KB |
Output is correct |
6 |
Correct |
772 ms |
24488 KB |
Output is correct |
7 |
Correct |
371 ms |
13236 KB |
Output is correct |
8 |
Correct |
67 ms |
3016 KB |
Output is correct |
9 |
Correct |
2452 ms |
52812 KB |
Output is correct |
10 |
Correct |
1689 ms |
45460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2881 ms |
54240 KB |
Output is correct |
2 |
Execution timed out |
3047 ms |
51860 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
452 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
516 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
5 ms |
860 KB |
Output is correct |
20 |
Correct |
6 ms |
860 KB |
Output is correct |
21 |
Correct |
5 ms |
856 KB |
Output is correct |
22 |
Correct |
21 ms |
1364 KB |
Output is correct |
23 |
Correct |
22 ms |
1240 KB |
Output is correct |
24 |
Correct |
21 ms |
1240 KB |
Output is correct |
25 |
Correct |
23 ms |
1240 KB |
Output is correct |
26 |
Correct |
24 ms |
1240 KB |
Output is correct |
27 |
Correct |
11 ms |
1236 KB |
Output is correct |
28 |
Correct |
11 ms |
1240 KB |
Output is correct |
29 |
Correct |
11 ms |
1240 KB |
Output is correct |
30 |
Correct |
53 ms |
2148 KB |
Output is correct |
31 |
Correct |
43 ms |
2260 KB |
Output is correct |
32 |
Correct |
49 ms |
2260 KB |
Output is correct |
33 |
Correct |
120 ms |
9400 KB |
Output is correct |
34 |
Correct |
143 ms |
9496 KB |
Output is correct |
35 |
Correct |
114 ms |
9144 KB |
Output is correct |
36 |
Correct |
647 ms |
18356 KB |
Output is correct |
37 |
Correct |
659 ms |
18312 KB |
Output is correct |
38 |
Correct |
661 ms |
18524 KB |
Output is correct |
39 |
Correct |
338 ms |
12196 KB |
Output is correct |
40 |
Correct |
355 ms |
12404 KB |
Output is correct |
41 |
Correct |
349 ms |
12380 KB |
Output is correct |
42 |
Correct |
271 ms |
12980 KB |
Output is correct |
43 |
Correct |
587 ms |
18148 KB |
Output is correct |
44 |
Correct |
604 ms |
18132 KB |
Output is correct |
45 |
Correct |
548 ms |
18028 KB |
Output is correct |
46 |
Correct |
547 ms |
18100 KB |
Output is correct |
47 |
Correct |
556 ms |
18148 KB |
Output is correct |
48 |
Correct |
545 ms |
18088 KB |
Output is correct |
49 |
Correct |
542 ms |
18100 KB |
Output is correct |
50 |
Correct |
530 ms |
18100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
452 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
516 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
5 ms |
860 KB |
Output is correct |
20 |
Correct |
6 ms |
860 KB |
Output is correct |
21 |
Correct |
5 ms |
856 KB |
Output is correct |
22 |
Correct |
21 ms |
1364 KB |
Output is correct |
23 |
Correct |
22 ms |
1240 KB |
Output is correct |
24 |
Correct |
21 ms |
1240 KB |
Output is correct |
25 |
Correct |
23 ms |
1240 KB |
Output is correct |
26 |
Correct |
24 ms |
1240 KB |
Output is correct |
27 |
Correct |
287 ms |
23444 KB |
Output is correct |
28 |
Correct |
285 ms |
24252 KB |
Output is correct |
29 |
Correct |
299 ms |
25804 KB |
Output is correct |
30 |
Correct |
302 ms |
24472 KB |
Output is correct |
31 |
Correct |
452 ms |
24212 KB |
Output is correct |
32 |
Correct |
1045 ms |
32020 KB |
Output is correct |
33 |
Correct |
500 ms |
24468 KB |
Output is correct |
34 |
Correct |
682 ms |
25748 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
603 ms |
18356 KB |
Output is correct |
37 |
Correct |
2784 ms |
54024 KB |
Output is correct |
38 |
Correct |
2788 ms |
54168 KB |
Output is correct |
39 |
Correct |
1930 ms |
48156 KB |
Output is correct |
40 |
Correct |
772 ms |
24488 KB |
Output is correct |
41 |
Correct |
371 ms |
13236 KB |
Output is correct |
42 |
Correct |
67 ms |
3016 KB |
Output is correct |
43 |
Correct |
2452 ms |
52812 KB |
Output is correct |
44 |
Correct |
1689 ms |
45460 KB |
Output is correct |
45 |
Correct |
2881 ms |
54240 KB |
Output is correct |
46 |
Execution timed out |
3047 ms |
51860 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |