#include<bits/stdc++.h>
using namespace std;
const int nmax=3e5+42,inf=1e9+42,MX=(1<<20)+42;
struct circle
{
int x,y,r,id;
};
int n;
circle inp[nmax],sorted_inp[nmax],other_sorted[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;
}
bool cmp_y(circle a,circle b)
{
if(a.y!=b.y)return a.y<b.y;
return a.id<b.id;
}
int outp[nmax];
vector< pair<int/*y*/,int/*id*/> > nodes[MX];
vector<int> prv[MX];
vector<int> nxt[MX];
vector<int> tree[MX];
void update(int node,int l,int r,int pos,circle cur)
{
//cout<<node<<" -> "<<cur.y<<" "<<cur.id<<endl;
nodes[node].push_back({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 build(int where,int node,int l,int r)
{
while(tree[where].size()<=node)tree[where].push_back(0);
tree[where][node]=r-l+1;
if(l==r)return;
int av=(l+r)/2;
build(where,node*2,l,av);
build(where,node*2+1,av+1,r);
}
void sub_tree(int where,int node,int l,int r,int pos)
{
while(l!=r)
{
tree[where][node]--;
if(l==r)return;
int av=(l+r)/2;
if(pos<=av)node=node*2,r=av;
else node=node*2+1,l=av+1;
}
}
int query(int where,int node,int l,int r,int lq,int rq)
{
if(tree[where][node]==0)return -1;
if(l==r)return l;
int av=(l+r)/2;
if(lq<=av)
{
int mem=query(where,node*2,l,av,lq,min(av,rq));
if(mem!=-1)return mem;
}
if(av<rq)
{
int mem=query(where,node*2+1,av+1,r,max(av+1,lq),rq);
if(mem!=-1)return mem;
}
return -1;
}
int find_first(int where,int start)
{
return query(where,1,0,nodes[where].size()-1,start,nodes[where].size()-1);
}
int pick(int a,int b)
{
long long sum=a;
sum=sum+b;
if(inf<sum)sum=inf;
if(-inf>sum)sum=-inf;
return sum;
}
void match(int node,int l,int r,int lq,int rq,circle cur)
{
if(tree[node].size()==0)return;
if(tree[node][1]==0)return;
if(l==lq&&r==rq)
{
int y1=pick(cur.y,-2*cur.r);
int y2=pick(cur.y,2*cur.r);
int start=lower_bound(nodes[node].begin(),nodes[node].end(),make_pair(y1,0))-nodes[node].begin();
if(start==nodes[node].size())return;
start=find_first(node,start);
/*
cout<<"circle "<<l<<" "<<r<<" "<<cur.id<<endl;
for(auto k:nodes[node])
cout<<k.first<<" "<<k.second<<"\t";cout<<endl;
cout<<"y1= "<<y1<<" y2= "<<y2<<" start= "<<start<<endl;
*/
if(start==-1)return;
vector<int> to_pop={};
while(start<nodes[node].size()&&nodes[node][start].first<=y2)
{
//cout<<"start= "<<start<<" "<<nodes[node][start].second<<" "<<inp[nodes[node][start].second].x<<" "<<inp[nodes[node][start].second].y<<" "<<inp[nodes[node][start].second].r<<endl;
if(outp[nodes[node][start].second]==0&&touch(inp[nodes[node][start].second],cur))
{
//cout<<"touch "<<nodes[node][start].second<<" "<<cur.id<<" "<<endl;
outp[nodes[node][start].second]=cur.id;
}
if(outp[nodes[node][start].second])to_pop.push_back(start);
start=nxt[node][start];
}
for(auto k:to_pop)
{
if(0<=prv[node][k])
{
nxt[node][prv[node][k]]=nxt[node][k];
}
if(nxt[node][k]<nodes[node].size())
{
prv[node][nxt[node][k]]=prv[node][k];
}
sub_tree(node,1,0,nodes[node].size()-1,k);
}
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=pick(sorted_inp[which].x,-2*sorted_inp[which].r);
int x2=pick(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("%i%i%i",&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],other_sorted[i]=inp[i];
sort(other_sorted+1,other_sorted+n+1,cmp_y);
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,other_sorted[i].x)-help_x;
update(1,1,n,pos,other_sorted[i]);
}
for(int i=1;i<MX;i++)
if(nodes[i].size())
{
for(int j=0;j<nodes[i].size();j++)
{
prv[i].push_back(j-1);
nxt[i].push_back(j+1);
}
build(i,1,0,nodes[i].size()-1);
}
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 'void build(int, int, int, int)':
circle_selection.cpp:56:29: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
56 | while(tree[where].size()<=node)tree[where].push_back(0);
| ~~~~~~~~~~~~~~~~~~^~~~~~
circle_selection.cpp: In function 'void match(int, int, int, int, int, circle)':
circle_selection.cpp:128:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
128 | if(start==nodes[node].size())return;
| ~~~~~^~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:143:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
143 | while(start<nodes[node].size()&&nodes[node][start].first<=y2)
| ~~~~~^~~~~~~~~~~~~~~~~~~
circle_selection.cpp:165:28: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
165 | if(nxt[node][k]<nodes[node].size())
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:230:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
230 | for(int j=0;j<nodes[i].size();j++)
| ~^~~~~~~~~~~~~~~~
circle_selection.cpp:242:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
242 | for(int i=1;i<=n;i++)printf("%i ",outp[i]);printf("\n");
| ^~~
circle_selection.cpp:242:48: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
242 | for(int i=1;i<=n;i++)printf("%i ",outp[i]);printf("\n");
| ^~~~~~
circle_selection.cpp:203:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
203 | scanf("%i",&n);
| ~~~~~^~~~~~~~~
circle_selection.cpp:206:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
206 | scanf("%i%i%i",&inp[i].x,&inp[i].y,&inp[i].r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
98808 KB |
Output is correct |
2 |
Correct |
69 ms |
98808 KB |
Output is correct |
3 |
Correct |
75 ms |
98808 KB |
Output is correct |
4 |
Correct |
70 ms |
98808 KB |
Output is correct |
5 |
Correct |
69 ms |
98808 KB |
Output is correct |
6 |
Correct |
77 ms |
98936 KB |
Output is correct |
7 |
Correct |
72 ms |
98936 KB |
Output is correct |
8 |
Correct |
69 ms |
98936 KB |
Output is correct |
9 |
Correct |
71 ms |
98888 KB |
Output is correct |
10 |
Correct |
70 ms |
98840 KB |
Output is correct |
11 |
Correct |
70 ms |
98944 KB |
Output is correct |
12 |
Correct |
69 ms |
98936 KB |
Output is correct |
13 |
Correct |
69 ms |
98936 KB |
Output is correct |
14 |
Correct |
71 ms |
98936 KB |
Output is correct |
15 |
Correct |
68 ms |
98952 KB |
Output is correct |
16 |
Correct |
72 ms |
99320 KB |
Output is correct |
17 |
Correct |
72 ms |
99320 KB |
Output is correct |
18 |
Correct |
73 ms |
99320 KB |
Output is correct |
19 |
Correct |
90 ms |
102648 KB |
Output is correct |
20 |
Correct |
87 ms |
102520 KB |
Output is correct |
21 |
Correct |
88 ms |
102648 KB |
Output is correct |
22 |
Correct |
89 ms |
102520 KB |
Output is correct |
23 |
Correct |
91 ms |
102696 KB |
Output is correct |
24 |
Correct |
90 ms |
102520 KB |
Output is correct |
25 |
Correct |
89 ms |
102524 KB |
Output is correct |
26 |
Correct |
89 ms |
102520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1603 ms |
377524 KB |
Output is correct |
2 |
Correct |
1650 ms |
377424 KB |
Output is correct |
3 |
Correct |
1749 ms |
377552 KB |
Output is correct |
4 |
Correct |
1711 ms |
376588 KB |
Output is correct |
5 |
Incorrect |
1646 ms |
360904 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
98808 KB |
Output is correct |
2 |
Correct |
801 ms |
174688 KB |
Output is correct |
3 |
Correct |
2638 ms |
376692 KB |
Output is correct |
4 |
Correct |
2774 ms |
378752 KB |
Output is correct |
5 |
Incorrect |
2431 ms |
370932 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2601 ms |
380120 KB |
Output is correct |
2 |
Correct |
2295 ms |
376652 KB |
Output is correct |
3 |
Incorrect |
1910 ms |
376792 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
98808 KB |
Output is correct |
2 |
Correct |
69 ms |
98808 KB |
Output is correct |
3 |
Correct |
75 ms |
98808 KB |
Output is correct |
4 |
Correct |
70 ms |
98808 KB |
Output is correct |
5 |
Correct |
69 ms |
98808 KB |
Output is correct |
6 |
Correct |
77 ms |
98936 KB |
Output is correct |
7 |
Correct |
72 ms |
98936 KB |
Output is correct |
8 |
Correct |
69 ms |
98936 KB |
Output is correct |
9 |
Correct |
71 ms |
98888 KB |
Output is correct |
10 |
Correct |
70 ms |
98840 KB |
Output is correct |
11 |
Correct |
70 ms |
98944 KB |
Output is correct |
12 |
Correct |
69 ms |
98936 KB |
Output is correct |
13 |
Correct |
69 ms |
98936 KB |
Output is correct |
14 |
Correct |
71 ms |
98936 KB |
Output is correct |
15 |
Correct |
68 ms |
98952 KB |
Output is correct |
16 |
Correct |
72 ms |
99320 KB |
Output is correct |
17 |
Correct |
72 ms |
99320 KB |
Output is correct |
18 |
Correct |
73 ms |
99320 KB |
Output is correct |
19 |
Correct |
90 ms |
102648 KB |
Output is correct |
20 |
Correct |
87 ms |
102520 KB |
Output is correct |
21 |
Correct |
88 ms |
102648 KB |
Output is correct |
22 |
Correct |
89 ms |
102520 KB |
Output is correct |
23 |
Correct |
91 ms |
102696 KB |
Output is correct |
24 |
Correct |
90 ms |
102520 KB |
Output is correct |
25 |
Correct |
89 ms |
102524 KB |
Output is correct |
26 |
Correct |
89 ms |
102520 KB |
Output is correct |
27 |
Correct |
107 ms |
106616 KB |
Output is correct |
28 |
Correct |
107 ms |
106616 KB |
Output is correct |
29 |
Correct |
110 ms |
106488 KB |
Output is correct |
30 |
Correct |
117 ms |
106488 KB |
Output is correct |
31 |
Correct |
123 ms |
106492 KB |
Output is correct |
32 |
Correct |
112 ms |
106488 KB |
Output is correct |
33 |
Correct |
531 ms |
175332 KB |
Output is correct |
34 |
Correct |
532 ms |
175460 KB |
Output is correct |
35 |
Correct |
520 ms |
175752 KB |
Output is correct |
36 |
Correct |
680 ms |
174992 KB |
Output is correct |
37 |
Correct |
686 ms |
175076 KB |
Output is correct |
38 |
Correct |
721 ms |
175192 KB |
Output is correct |
39 |
Incorrect |
566 ms |
161252 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
98808 KB |
Output is correct |
2 |
Correct |
69 ms |
98808 KB |
Output is correct |
3 |
Correct |
75 ms |
98808 KB |
Output is correct |
4 |
Correct |
70 ms |
98808 KB |
Output is correct |
5 |
Correct |
69 ms |
98808 KB |
Output is correct |
6 |
Correct |
77 ms |
98936 KB |
Output is correct |
7 |
Correct |
72 ms |
98936 KB |
Output is correct |
8 |
Correct |
69 ms |
98936 KB |
Output is correct |
9 |
Correct |
71 ms |
98888 KB |
Output is correct |
10 |
Correct |
70 ms |
98840 KB |
Output is correct |
11 |
Correct |
70 ms |
98944 KB |
Output is correct |
12 |
Correct |
69 ms |
98936 KB |
Output is correct |
13 |
Correct |
69 ms |
98936 KB |
Output is correct |
14 |
Correct |
71 ms |
98936 KB |
Output is correct |
15 |
Correct |
68 ms |
98952 KB |
Output is correct |
16 |
Correct |
72 ms |
99320 KB |
Output is correct |
17 |
Correct |
72 ms |
99320 KB |
Output is correct |
18 |
Correct |
73 ms |
99320 KB |
Output is correct |
19 |
Correct |
90 ms |
102648 KB |
Output is correct |
20 |
Correct |
87 ms |
102520 KB |
Output is correct |
21 |
Correct |
88 ms |
102648 KB |
Output is correct |
22 |
Correct |
89 ms |
102520 KB |
Output is correct |
23 |
Correct |
91 ms |
102696 KB |
Output is correct |
24 |
Correct |
90 ms |
102520 KB |
Output is correct |
25 |
Correct |
89 ms |
102524 KB |
Output is correct |
26 |
Correct |
89 ms |
102520 KB |
Output is correct |
27 |
Correct |
1603 ms |
377524 KB |
Output is correct |
28 |
Correct |
1650 ms |
377424 KB |
Output is correct |
29 |
Correct |
1749 ms |
377552 KB |
Output is correct |
30 |
Correct |
1711 ms |
376588 KB |
Output is correct |
31 |
Incorrect |
1646 ms |
360904 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |