#include<bits/stdc++.h>
#define int long long
using namespace std;
const int nmax=3e5+42;
struct circle
{
int x,y,r,id;
};
int n;
circle inp[nmax],sorted_inp[nmax];
bool touch(circle a,circle b)
{
long long d=1LL*(a.x-b.x)*(a.x-b.x)+1LL*(a.y-b.y)*(a.y-b.y);
long long mx=a.r+b.r;
mx=mx*mx;
return d<=mx;
}
bool cmp(circle a,circle b)
{
if(a.r!=b.r)return a.r>b.r;
return a.id<b.id;
}
int outp[nmax];
set< pair<int/*y*/,int/*id*/> > tree[nmax*4];
void update(int node,int l,int r,int pos,circle cur)
{
//cout<<node<<" -> "<<cur.y<<" "<<cur.id<<endl;
tree[node].insert({cur.y,cur.id});
if(l==r)return;
int av=(l+r)/2;
if(pos<=av)update(node*2,l,av,pos,cur);
else update(node*2+1,av+1,r,pos,cur);
}
void match(int node,int l,int r,int lq,int rq,circle cur)
{
if(tree[node].size()==0)return;
int y1=cur.y-2*cur.r;
int y2=cur.y+2*cur.r;
//cout<<y1<<" "<<y2<<endl;
set< pair<int/*y*/,int/*id*/> >::iterator it=tree[node].lower_bound({y1,0});
vector< pair<int/*y*/,int/*id*/> > to_pop={};
while(it!=tree[node].end())
{
pair<int/*y*/,int/*id*/> info=*it;
if(info.first>y2)break;
if(outp[info.second]==0)
{
if(touch(inp[info.second],cur))
{
//cout<<"touch "<<info.second<<" "<<cur.id<<" "<<endl;
outp[info.second]=cur.id;
}
}
if(outp[info.second])to_pop.push_back(info);
it++;
}
for(auto k:to_pop)
tree[node].erase(k);
if(l==lq&&r==rq)return;
int av=(l+r)/2;
if(lq<=av)match(node*2,l,av,lq,min(av,rq),cur);
if(av<rq)match(node*2+1,av+1,r,max(av+1,lq),rq,cur);
}
int help_x[nmax];
void push(int which)
{
outp[sorted_inp[which].id]=sorted_inp[which].id;
int x1=sorted_inp[which].x-2*sorted_inp[which].r;
int x2=sorted_inp[which].x+2*sorted_inp[which].r;
int le=lower_bound(help_x+1,help_x+n+1,x1)-help_x;
int ri=upper_bound(help_x+1,help_x+n+1,x2)-help_x;
ri--;
//cout<<"le= "<<le<<" ri= "<<ri<<endl;
if(le>ri)return;
match(1,1,n,le,ri,sorted_inp[which]);
}
signed main()
{
scanf("%i",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld%lld%lld",&inp[i].x,&inp[i].y,&inp[i].r);
inp[i].id=i;
}
for(int i=1;i<=n;i++)sorted_inp[i]=inp[i];
sort(sorted_inp+1,sorted_inp+n+1,cmp);
for(int i=1;i<=n;i++)help_x[i]=sorted_inp[i].x;
sort(help_x+1,help_x+n+1);
for(int i=1;i<=n;i++)
{
int pos=lower_bound(help_x+1,help_x+n+1,sorted_inp[i].x)-help_x;
update(1,1,n,pos,sorted_inp[i]);
}
for(int i=1;i<=n;i++)
if(outp[sorted_inp[i].id]==0)
push(i);
for(int i=1;i<=n;i++)printf("%i ",outp[i]);printf("\n");
return 0;
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:115:13: warning: format '%i' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
115 | scanf("%i",&n);
| ~^ ~~
| | |
| | long long int*
| int*
| %lli
circle_selection.cpp:141:35: warning: format '%i' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
141 | for(int i=1;i<=n;i++)printf("%i ",outp[i]);printf("\n");
| ~^ ~~~~~~~
| | |
| int long long int
| %lli
circle_selection.cpp:141:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
141 | for(int i=1;i<=n;i++)printf("%i ",outp[i]);printf("\n");
| ^~~
circle_selection.cpp:141:48: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
141 | for(int i=1;i<=n;i++)printf("%i ",outp[i]);printf("\n");
| ^~~~~~
circle_selection.cpp:115:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
115 | scanf("%i",&n);
| ~~~~~^~~~~~~~~
circle_selection.cpp:118:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
118 | scanf("%lld%lld%lld",&inp[i].x,&inp[i].y,&inp[i].r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
56696 KB |
Output is correct |
2 |
Correct |
36 ms |
56696 KB |
Output is correct |
3 |
Correct |
36 ms |
56696 KB |
Output is correct |
4 |
Correct |
35 ms |
56704 KB |
Output is correct |
5 |
Correct |
40 ms |
56704 KB |
Output is correct |
6 |
Correct |
40 ms |
56824 KB |
Output is correct |
7 |
Correct |
40 ms |
56696 KB |
Output is correct |
8 |
Correct |
37 ms |
56704 KB |
Output is correct |
9 |
Correct |
36 ms |
56696 KB |
Output is correct |
10 |
Correct |
43 ms |
56824 KB |
Output is correct |
11 |
Correct |
41 ms |
56696 KB |
Output is correct |
12 |
Correct |
40 ms |
56704 KB |
Output is correct |
13 |
Correct |
37 ms |
56696 KB |
Output is correct |
14 |
Correct |
36 ms |
56824 KB |
Output is correct |
15 |
Correct |
36 ms |
56696 KB |
Output is correct |
16 |
Correct |
41 ms |
57464 KB |
Output is correct |
17 |
Correct |
40 ms |
57464 KB |
Output is correct |
18 |
Correct |
42 ms |
57596 KB |
Output is correct |
19 |
Correct |
59 ms |
61608 KB |
Output is correct |
20 |
Correct |
59 ms |
61692 KB |
Output is correct |
21 |
Correct |
58 ms |
61560 KB |
Output is correct |
22 |
Correct |
74 ms |
61432 KB |
Output is correct |
23 |
Correct |
79 ms |
61560 KB |
Output is correct |
24 |
Correct |
77 ms |
61432 KB |
Output is correct |
25 |
Correct |
75 ms |
61432 KB |
Output is correct |
26 |
Correct |
73 ms |
61432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3078 ms |
336872 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
56696 KB |
Output is correct |
2 |
Execution timed out |
3073 ms |
175384 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3075 ms |
328608 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
56696 KB |
Output is correct |
2 |
Correct |
36 ms |
56696 KB |
Output is correct |
3 |
Correct |
36 ms |
56696 KB |
Output is correct |
4 |
Correct |
35 ms |
56704 KB |
Output is correct |
5 |
Correct |
40 ms |
56704 KB |
Output is correct |
6 |
Correct |
40 ms |
56824 KB |
Output is correct |
7 |
Correct |
40 ms |
56696 KB |
Output is correct |
8 |
Correct |
37 ms |
56704 KB |
Output is correct |
9 |
Correct |
36 ms |
56696 KB |
Output is correct |
10 |
Correct |
43 ms |
56824 KB |
Output is correct |
11 |
Correct |
41 ms |
56696 KB |
Output is correct |
12 |
Correct |
40 ms |
56704 KB |
Output is correct |
13 |
Correct |
37 ms |
56696 KB |
Output is correct |
14 |
Correct |
36 ms |
56824 KB |
Output is correct |
15 |
Correct |
36 ms |
56696 KB |
Output is correct |
16 |
Correct |
41 ms |
57464 KB |
Output is correct |
17 |
Correct |
40 ms |
57464 KB |
Output is correct |
18 |
Correct |
42 ms |
57596 KB |
Output is correct |
19 |
Correct |
59 ms |
61608 KB |
Output is correct |
20 |
Correct |
59 ms |
61692 KB |
Output is correct |
21 |
Correct |
58 ms |
61560 KB |
Output is correct |
22 |
Correct |
74 ms |
61432 KB |
Output is correct |
23 |
Correct |
79 ms |
61560 KB |
Output is correct |
24 |
Correct |
77 ms |
61432 KB |
Output is correct |
25 |
Correct |
75 ms |
61432 KB |
Output is correct |
26 |
Correct |
73 ms |
61432 KB |
Output is correct |
27 |
Correct |
103 ms |
67192 KB |
Output is correct |
28 |
Correct |
107 ms |
67320 KB |
Output is correct |
29 |
Correct |
104 ms |
67192 KB |
Output is correct |
30 |
Correct |
157 ms |
66808 KB |
Output is correct |
31 |
Correct |
137 ms |
66812 KB |
Output is correct |
32 |
Correct |
140 ms |
66808 KB |
Output is correct |
33 |
Correct |
1471 ms |
180640 KB |
Output is correct |
34 |
Correct |
1440 ms |
180740 KB |
Output is correct |
35 |
Correct |
1557 ms |
180984 KB |
Output is correct |
36 |
Correct |
2796 ms |
178424 KB |
Output is correct |
37 |
Correct |
2724 ms |
178536 KB |
Output is correct |
38 |
Correct |
2852 ms |
178688 KB |
Output is correct |
39 |
Execution timed out |
3083 ms |
175480 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
56696 KB |
Output is correct |
2 |
Correct |
36 ms |
56696 KB |
Output is correct |
3 |
Correct |
36 ms |
56696 KB |
Output is correct |
4 |
Correct |
35 ms |
56704 KB |
Output is correct |
5 |
Correct |
40 ms |
56704 KB |
Output is correct |
6 |
Correct |
40 ms |
56824 KB |
Output is correct |
7 |
Correct |
40 ms |
56696 KB |
Output is correct |
8 |
Correct |
37 ms |
56704 KB |
Output is correct |
9 |
Correct |
36 ms |
56696 KB |
Output is correct |
10 |
Correct |
43 ms |
56824 KB |
Output is correct |
11 |
Correct |
41 ms |
56696 KB |
Output is correct |
12 |
Correct |
40 ms |
56704 KB |
Output is correct |
13 |
Correct |
37 ms |
56696 KB |
Output is correct |
14 |
Correct |
36 ms |
56824 KB |
Output is correct |
15 |
Correct |
36 ms |
56696 KB |
Output is correct |
16 |
Correct |
41 ms |
57464 KB |
Output is correct |
17 |
Correct |
40 ms |
57464 KB |
Output is correct |
18 |
Correct |
42 ms |
57596 KB |
Output is correct |
19 |
Correct |
59 ms |
61608 KB |
Output is correct |
20 |
Correct |
59 ms |
61692 KB |
Output is correct |
21 |
Correct |
58 ms |
61560 KB |
Output is correct |
22 |
Correct |
74 ms |
61432 KB |
Output is correct |
23 |
Correct |
79 ms |
61560 KB |
Output is correct |
24 |
Correct |
77 ms |
61432 KB |
Output is correct |
25 |
Correct |
75 ms |
61432 KB |
Output is correct |
26 |
Correct |
73 ms |
61432 KB |
Output is correct |
27 |
Execution timed out |
3078 ms |
336872 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |