#include<bits/stdc++.h>
using namespace std;
const int nmax=3e5+42,inf=1e9+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];
vector< pair<int/*y*/,int/*id*/> > nodes[nmax*4];
vector<int> prv[nmax*4];
vector<int> nxt[nmax*4];
vector<int> tree[nmax*4];
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)
{
tree[where][node]--;
if(l==r)return;
int av=(l+r)/2;
if(pos<=av)sub_tree(where,node*2,l,av,pos);
else sub_tree(where,node*2+1,av+1,r,pos);
}
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];
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<=4*n;i++)
if(nodes[i].size())
{
sort(nodes[i].begin(),nodes[i].end());
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:51:29: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
51 | 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:120: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]
120 | if(start==nodes[node].size())return;
| ~~~~~^~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:135: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]
135 | while(start<nodes[node].size()&&nodes[node][start].first<=y2)
| ~~~~~^~~~~~~~~~~~~~~~~~~
circle_selection.cpp:157: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]
157 | if(nxt[node][k]<nodes[node].size())
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:221: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]
221 | for(int j=0;j<nodes[i].size();j++)
| ~^~~~~~~~~~~~~~~~
circle_selection.cpp:233:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
233 | for(int i=1;i<=n;i++)printf("%i ",outp[i]);printf("\n");
| ^~~
circle_selection.cpp:233:48: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
233 | for(int i=1;i<=n;i++)printf("%i ",outp[i]);printf("\n");
| ^~~~~~
circle_selection.cpp:195:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
195 | scanf("%i",&n);
| ~~~~~^~~~~~~~~
circle_selection.cpp:198:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
198 | scanf("%i%i%i",&inp[i].x,&inp[i].y,&inp[i].r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
113016 KB |
Output is correct |
2 |
Correct |
77 ms |
113016 KB |
Output is correct |
3 |
Correct |
78 ms |
113048 KB |
Output is correct |
4 |
Correct |
84 ms |
113020 KB |
Output is correct |
5 |
Correct |
81 ms |
113132 KB |
Output is correct |
6 |
Correct |
73 ms |
113144 KB |
Output is correct |
7 |
Correct |
73 ms |
113144 KB |
Output is correct |
8 |
Correct |
71 ms |
113144 KB |
Output is correct |
9 |
Correct |
78 ms |
113176 KB |
Output is correct |
10 |
Correct |
79 ms |
113184 KB |
Output is correct |
11 |
Correct |
77 ms |
113052 KB |
Output is correct |
12 |
Correct |
82 ms |
113144 KB |
Output is correct |
13 |
Correct |
78 ms |
113144 KB |
Output is correct |
14 |
Correct |
79 ms |
113144 KB |
Output is correct |
15 |
Correct |
82 ms |
113144 KB |
Output is correct |
16 |
Correct |
84 ms |
113528 KB |
Output is correct |
17 |
Correct |
82 ms |
113616 KB |
Output is correct |
18 |
Correct |
81 ms |
113528 KB |
Output is correct |
19 |
Correct |
95 ms |
116728 KB |
Output is correct |
20 |
Correct |
96 ms |
116728 KB |
Output is correct |
21 |
Correct |
96 ms |
116728 KB |
Output is correct |
22 |
Correct |
98 ms |
116572 KB |
Output is correct |
23 |
Correct |
99 ms |
116600 KB |
Output is correct |
24 |
Correct |
98 ms |
116600 KB |
Output is correct |
25 |
Correct |
97 ms |
116600 KB |
Output is correct |
26 |
Correct |
97 ms |
116600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2007 ms |
388172 KB |
Output is correct |
2 |
Correct |
1885 ms |
393020 KB |
Output is correct |
3 |
Correct |
1891 ms |
393292 KB |
Output is correct |
4 |
Correct |
1904 ms |
393076 KB |
Output is correct |
5 |
Correct |
1905 ms |
375760 KB |
Output is correct |
6 |
Correct |
2089 ms |
389072 KB |
Output is correct |
7 |
Correct |
1905 ms |
386972 KB |
Output is correct |
8 |
Correct |
1944 ms |
387960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
113020 KB |
Output is correct |
2 |
Correct |
842 ms |
186792 KB |
Output is correct |
3 |
Correct |
2916 ms |
388048 KB |
Output is correct |
4 |
Correct |
2805 ms |
392716 KB |
Output is correct |
5 |
Correct |
2730 ms |
387404 KB |
Output is correct |
6 |
Correct |
1350 ms |
250840 KB |
Output is correct |
7 |
Correct |
685 ms |
181728 KB |
Output is correct |
8 |
Correct |
160 ms |
126772 KB |
Output is correct |
9 |
Correct |
2831 ms |
391536 KB |
Output is correct |
10 |
Correct |
2717 ms |
393028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2750 ms |
384892 KB |
Output is correct |
2 |
Correct |
2423 ms |
391672 KB |
Output is correct |
3 |
Correct |
2037 ms |
393032 KB |
Output is correct |
4 |
Correct |
2364 ms |
392400 KB |
Output is correct |
5 |
Correct |
2447 ms |
392672 KB |
Output is correct |
6 |
Correct |
1940 ms |
393116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
113016 KB |
Output is correct |
2 |
Correct |
77 ms |
113016 KB |
Output is correct |
3 |
Correct |
78 ms |
113048 KB |
Output is correct |
4 |
Correct |
84 ms |
113020 KB |
Output is correct |
5 |
Correct |
81 ms |
113132 KB |
Output is correct |
6 |
Correct |
73 ms |
113144 KB |
Output is correct |
7 |
Correct |
73 ms |
113144 KB |
Output is correct |
8 |
Correct |
71 ms |
113144 KB |
Output is correct |
9 |
Correct |
78 ms |
113176 KB |
Output is correct |
10 |
Correct |
79 ms |
113184 KB |
Output is correct |
11 |
Correct |
77 ms |
113052 KB |
Output is correct |
12 |
Correct |
82 ms |
113144 KB |
Output is correct |
13 |
Correct |
78 ms |
113144 KB |
Output is correct |
14 |
Correct |
79 ms |
113144 KB |
Output is correct |
15 |
Correct |
82 ms |
113144 KB |
Output is correct |
16 |
Correct |
84 ms |
113528 KB |
Output is correct |
17 |
Correct |
82 ms |
113616 KB |
Output is correct |
18 |
Correct |
81 ms |
113528 KB |
Output is correct |
19 |
Correct |
95 ms |
116728 KB |
Output is correct |
20 |
Correct |
96 ms |
116728 KB |
Output is correct |
21 |
Correct |
96 ms |
116728 KB |
Output is correct |
22 |
Correct |
98 ms |
116572 KB |
Output is correct |
23 |
Correct |
99 ms |
116600 KB |
Output is correct |
24 |
Correct |
98 ms |
116600 KB |
Output is correct |
25 |
Correct |
97 ms |
116600 KB |
Output is correct |
26 |
Correct |
97 ms |
116600 KB |
Output is correct |
27 |
Correct |
114 ms |
120568 KB |
Output is correct |
28 |
Correct |
121 ms |
120696 KB |
Output is correct |
29 |
Correct |
122 ms |
120824 KB |
Output is correct |
30 |
Correct |
133 ms |
120440 KB |
Output is correct |
31 |
Correct |
125 ms |
120568 KB |
Output is correct |
32 |
Correct |
126 ms |
120568 KB |
Output is correct |
33 |
Correct |
577 ms |
189864 KB |
Output is correct |
34 |
Correct |
593 ms |
189924 KB |
Output is correct |
35 |
Correct |
592 ms |
189960 KB |
Output is correct |
36 |
Correct |
783 ms |
188900 KB |
Output is correct |
37 |
Correct |
776 ms |
189028 KB |
Output is correct |
38 |
Correct |
792 ms |
189024 KB |
Output is correct |
39 |
Correct |
645 ms |
173980 KB |
Output is correct |
40 |
Correct |
635 ms |
174180 KB |
Output is correct |
41 |
Correct |
635 ms |
174044 KB |
Output is correct |
42 |
Correct |
502 ms |
171340 KB |
Output is correct |
43 |
Correct |
704 ms |
189032 KB |
Output is correct |
44 |
Correct |
695 ms |
189160 KB |
Output is correct |
45 |
Correct |
700 ms |
189112 KB |
Output is correct |
46 |
Correct |
695 ms |
188980 KB |
Output is correct |
47 |
Correct |
728 ms |
189080 KB |
Output is correct |
48 |
Correct |
717 ms |
189024 KB |
Output is correct |
49 |
Correct |
711 ms |
188976 KB |
Output is correct |
50 |
Correct |
710 ms |
188936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
113016 KB |
Output is correct |
2 |
Correct |
77 ms |
113016 KB |
Output is correct |
3 |
Correct |
78 ms |
113048 KB |
Output is correct |
4 |
Correct |
84 ms |
113020 KB |
Output is correct |
5 |
Correct |
81 ms |
113132 KB |
Output is correct |
6 |
Correct |
73 ms |
113144 KB |
Output is correct |
7 |
Correct |
73 ms |
113144 KB |
Output is correct |
8 |
Correct |
71 ms |
113144 KB |
Output is correct |
9 |
Correct |
78 ms |
113176 KB |
Output is correct |
10 |
Correct |
79 ms |
113184 KB |
Output is correct |
11 |
Correct |
77 ms |
113052 KB |
Output is correct |
12 |
Correct |
82 ms |
113144 KB |
Output is correct |
13 |
Correct |
78 ms |
113144 KB |
Output is correct |
14 |
Correct |
79 ms |
113144 KB |
Output is correct |
15 |
Correct |
82 ms |
113144 KB |
Output is correct |
16 |
Correct |
84 ms |
113528 KB |
Output is correct |
17 |
Correct |
82 ms |
113616 KB |
Output is correct |
18 |
Correct |
81 ms |
113528 KB |
Output is correct |
19 |
Correct |
95 ms |
116728 KB |
Output is correct |
20 |
Correct |
96 ms |
116728 KB |
Output is correct |
21 |
Correct |
96 ms |
116728 KB |
Output is correct |
22 |
Correct |
98 ms |
116572 KB |
Output is correct |
23 |
Correct |
99 ms |
116600 KB |
Output is correct |
24 |
Correct |
98 ms |
116600 KB |
Output is correct |
25 |
Correct |
97 ms |
116600 KB |
Output is correct |
26 |
Correct |
97 ms |
116600 KB |
Output is correct |
27 |
Correct |
2007 ms |
388172 KB |
Output is correct |
28 |
Correct |
1885 ms |
393020 KB |
Output is correct |
29 |
Correct |
1891 ms |
393292 KB |
Output is correct |
30 |
Correct |
1904 ms |
393076 KB |
Output is correct |
31 |
Correct |
1905 ms |
375760 KB |
Output is correct |
32 |
Correct |
2089 ms |
389072 KB |
Output is correct |
33 |
Correct |
1905 ms |
386972 KB |
Output is correct |
34 |
Correct |
1944 ms |
387960 KB |
Output is correct |
35 |
Correct |
80 ms |
113020 KB |
Output is correct |
36 |
Correct |
842 ms |
186792 KB |
Output is correct |
37 |
Correct |
2916 ms |
388048 KB |
Output is correct |
38 |
Correct |
2805 ms |
392716 KB |
Output is correct |
39 |
Correct |
2730 ms |
387404 KB |
Output is correct |
40 |
Correct |
1350 ms |
250840 KB |
Output is correct |
41 |
Correct |
685 ms |
181728 KB |
Output is correct |
42 |
Correct |
160 ms |
126772 KB |
Output is correct |
43 |
Correct |
2831 ms |
391536 KB |
Output is correct |
44 |
Correct |
2717 ms |
393028 KB |
Output is correct |
45 |
Correct |
2750 ms |
384892 KB |
Output is correct |
46 |
Correct |
2423 ms |
391672 KB |
Output is correct |
47 |
Correct |
2037 ms |
393032 KB |
Output is correct |
48 |
Correct |
2364 ms |
392400 KB |
Output is correct |
49 |
Correct |
2447 ms |
392672 KB |
Output is correct |
50 |
Correct |
1940 ms |
393116 KB |
Output is correct |
51 |
Correct |
114 ms |
120568 KB |
Output is correct |
52 |
Correct |
121 ms |
120696 KB |
Output is correct |
53 |
Correct |
122 ms |
120824 KB |
Output is correct |
54 |
Correct |
133 ms |
120440 KB |
Output is correct |
55 |
Correct |
125 ms |
120568 KB |
Output is correct |
56 |
Correct |
126 ms |
120568 KB |
Output is correct |
57 |
Correct |
577 ms |
189864 KB |
Output is correct |
58 |
Correct |
593 ms |
189924 KB |
Output is correct |
59 |
Correct |
592 ms |
189960 KB |
Output is correct |
60 |
Correct |
783 ms |
188900 KB |
Output is correct |
61 |
Correct |
776 ms |
189028 KB |
Output is correct |
62 |
Correct |
792 ms |
189024 KB |
Output is correct |
63 |
Correct |
645 ms |
173980 KB |
Output is correct |
64 |
Correct |
635 ms |
174180 KB |
Output is correct |
65 |
Correct |
635 ms |
174044 KB |
Output is correct |
66 |
Correct |
502 ms |
171340 KB |
Output is correct |
67 |
Correct |
704 ms |
189032 KB |
Output is correct |
68 |
Correct |
695 ms |
189160 KB |
Output is correct |
69 |
Correct |
700 ms |
189112 KB |
Output is correct |
70 |
Correct |
695 ms |
188980 KB |
Output is correct |
71 |
Correct |
728 ms |
189080 KB |
Output is correct |
72 |
Correct |
717 ms |
189024 KB |
Output is correct |
73 |
Correct |
711 ms |
188976 KB |
Output is correct |
74 |
Correct |
710 ms |
188936 KB |
Output is correct |
75 |
Correct |
1913 ms |
395608 KB |
Output is correct |
76 |
Correct |
1894 ms |
395480 KB |
Output is correct |
77 |
Correct |
1912 ms |
395076 KB |
Output is correct |
78 |
Correct |
1936 ms |
395324 KB |
Output is correct |
79 |
Correct |
1931 ms |
393652 KB |
Output is correct |
80 |
Correct |
1878 ms |
394968 KB |
Output is correct |
81 |
Correct |
2832 ms |
392968 KB |
Output is correct |
82 |
Correct |
2774 ms |
392652 KB |
Output is correct |
83 |
Correct |
2828 ms |
392824 KB |
Output is correct |
84 |
Execution timed out |
3101 ms |
393180 KB |
Time limit exceeded |
85 |
Halted |
0 ms |
0 KB |
- |