#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(){
}
void full(){
}
int main(){
cin>>N;
bool s2 = true;
bool s4 = false;
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(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 |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
0 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 |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 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 |
860 KB |
Output is correct |
20 |
Correct |
5 ms |
832 KB |
Output is correct |
21 |
Correct |
8 ms |
860 KB |
Output is correct |
22 |
Correct |
21 ms |
860 KB |
Output is correct |
23 |
Correct |
23 ms |
856 KB |
Output is correct |
24 |
Correct |
22 ms |
860 KB |
Output is correct |
25 |
Correct |
22 ms |
860 KB |
Output is correct |
26 |
Correct |
22 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
828 ms |
60408 KB |
Output is correct |
2 |
Correct |
860 ms |
57276 KB |
Output is correct |
3 |
Correct |
830 ms |
60528 KB |
Output is correct |
4 |
Correct |
850 ms |
60832 KB |
Output is correct |
5 |
Correct |
634 ms |
54104 KB |
Output is correct |
6 |
Correct |
636 ms |
55156 KB |
Output is correct |
7 |
Correct |
630 ms |
54256 KB |
Output is correct |
8 |
Correct |
630 ms |
54064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
187 ms |
19160 KB |
Output is correct |
3 |
Correct |
672 ms |
61608 KB |
Output is correct |
4 |
Correct |
669 ms |
60840 KB |
Output is correct |
5 |
Correct |
704 ms |
58272 KB |
Output is correct |
6 |
Correct |
311 ms |
32944 KB |
Output is correct |
7 |
Correct |
143 ms |
16824 KB |
Output is correct |
8 |
Correct |
24 ms |
3524 KB |
Output is correct |
9 |
Correct |
648 ms |
61180 KB |
Output is correct |
10 |
Correct |
762 ms |
60072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
623 ms |
56032 KB |
Output is correct |
2 |
Correct |
542 ms |
60072 KB |
Output is correct |
3 |
Incorrect |
805 ms |
60072 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
0 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 |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 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 |
860 KB |
Output is correct |
20 |
Correct |
5 ms |
832 KB |
Output is correct |
21 |
Correct |
8 ms |
860 KB |
Output is correct |
22 |
Correct |
21 ms |
860 KB |
Output is correct |
23 |
Correct |
23 ms |
856 KB |
Output is correct |
24 |
Correct |
22 ms |
860 KB |
Output is correct |
25 |
Correct |
22 ms |
860 KB |
Output is correct |
26 |
Correct |
22 ms |
860 KB |
Output is correct |
27 |
Incorrect |
20 ms |
2608 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
0 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 |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 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 |
860 KB |
Output is correct |
20 |
Correct |
5 ms |
832 KB |
Output is correct |
21 |
Correct |
8 ms |
860 KB |
Output is correct |
22 |
Correct |
21 ms |
860 KB |
Output is correct |
23 |
Correct |
23 ms |
856 KB |
Output is correct |
24 |
Correct |
22 ms |
860 KB |
Output is correct |
25 |
Correct |
22 ms |
860 KB |
Output is correct |
26 |
Correct |
22 ms |
860 KB |
Output is correct |
27 |
Correct |
828 ms |
60408 KB |
Output is correct |
28 |
Correct |
860 ms |
57276 KB |
Output is correct |
29 |
Correct |
830 ms |
60528 KB |
Output is correct |
30 |
Correct |
850 ms |
60832 KB |
Output is correct |
31 |
Correct |
634 ms |
54104 KB |
Output is correct |
32 |
Correct |
636 ms |
55156 KB |
Output is correct |
33 |
Correct |
630 ms |
54256 KB |
Output is correct |
34 |
Correct |
630 ms |
54064 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
187 ms |
19160 KB |
Output is correct |
37 |
Correct |
672 ms |
61608 KB |
Output is correct |
38 |
Correct |
669 ms |
60840 KB |
Output is correct |
39 |
Correct |
704 ms |
58272 KB |
Output is correct |
40 |
Correct |
311 ms |
32944 KB |
Output is correct |
41 |
Correct |
143 ms |
16824 KB |
Output is correct |
42 |
Correct |
24 ms |
3524 KB |
Output is correct |
43 |
Correct |
648 ms |
61180 KB |
Output is correct |
44 |
Correct |
762 ms |
60072 KB |
Output is correct |
45 |
Correct |
623 ms |
56032 KB |
Output is correct |
46 |
Correct |
542 ms |
60072 KB |
Output is correct |
47 |
Incorrect |
805 ms |
60072 KB |
Output isn't correct |
48 |
Halted |
0 ms |
0 KB |
- |