#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize ("unroll-loops")
#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> fenwick[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);
}
int SZ[nmax];
void upd(int where,int j,int val)
{
j++;
while(j<=SZ[nodes[where].size()])
{
fenwick[where][j]+=val;
j=j+(j&(-j));
}
}
int LST_SEEN[nmax];
void build(int where)
{
for(int i=0;i<=SZ[nodes[where].size()];i++)fenwick[where].push_back(0);
if(LST_SEEN[nodes[where].size()])
{
for(int j=1;j<=SZ[nodes[where].size()];j++)fenwick[where][j]=fenwick[LST_SEEN[nodes[where].size()]][j];
}
else
{
for(int i=0;i<nodes[where].size();i++)
upd(where,i,1);
}
LST_SEEN[nodes[where].size()]=where;
}
void sub_tree(int where,int pos)
{
upd(where,pos,-1);
}
int query(int where,int pos)
{
pos++;
int ret=0;
while(pos)
{
ret=ret+fenwick[where][pos];
pos=pos-(pos&(-pos));
}
return ret;
}
int bits[nmax];
int find_first(int where,int start)
{
int sum=query(where,start-1);
//cout<<"find_first "<<where<<" "<<start<<" "<<sum<<endl;
if(sum==fenwick[where][SZ[nodes[where].size()]])return -1;
int pos=0;
for(int j=bits[nodes[where].size()]-1;j>=0;j--)
if(fenwick[where][pos+(1<<j)]<=sum)
{
sum=sum-fenwick[where][pos+(1<<j)];
pos=pos+(1<<j);
}
//cout<<"pos= "<<pos<<endl;
return pos;
}
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(fenwick[node].size()==0)return;
if(fenwick[node][SZ[nodes[node].size()]]==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,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]);
}
int st=0;
for(int i=1;i<=n;i++)
{
if((1<<st)<i)st++;
SZ[i]=1<<st;
bits[i]=st;
//cout<<i<<" -> "<<SZ[i]<<" "<<bits[i]<<endl;
}
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);
}
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)':
circle_selection.cpp:84:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for(int i=0;i<nodes[where].size();i++)
| ~^~~~~~~~~~~~~~~~~~~~
circle_selection.cpp: In function 'void match(int, int, int, int, int, circle)':
circle_selection.cpp:157: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]
157 | if(start==nodes[node].size())return;
| ~~~~~^~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:172: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]
172 | while(start<nodes[node].size()&&nodes[node][start].first<=y2)
| ~~~~~^~~~~~~~~~~~~~~~~~~
circle_selection.cpp:194: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]
194 | if(nxt[node][k]<nodes[node].size())
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:270: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]
270 | for(int j=0;j<nodes[i].size();j++)
| ~^~~~~~~~~~~~~~~~
circle_selection.cpp:282:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
282 | for(int i=1;i<=n;i++)printf("%i ",outp[i]);printf("\n");
| ^~~
circle_selection.cpp:282:48: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
282 | for(int i=1;i<=n;i++)printf("%i ",outp[i]);printf("\n");
| ^~~~~~
circle_selection.cpp:232:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
232 | scanf("%i",&n);
| ~~~~~^~~~~~~~~
circle_selection.cpp:235:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
235 | scanf("%i%i%i",&inp[i].x,&inp[i].y,&inp[i].r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
98808 KB |
Output is correct |
2 |
Correct |
73 ms |
98812 KB |
Output is correct |
3 |
Correct |
72 ms |
98808 KB |
Output is correct |
4 |
Correct |
74 ms |
98864 KB |
Output is correct |
5 |
Correct |
72 ms |
98808 KB |
Output is correct |
6 |
Correct |
72 ms |
98936 KB |
Output is correct |
7 |
Correct |
73 ms |
98936 KB |
Output is correct |
8 |
Correct |
74 ms |
98936 KB |
Output is correct |
9 |
Correct |
73 ms |
98936 KB |
Output is correct |
10 |
Correct |
73 ms |
98936 KB |
Output is correct |
11 |
Correct |
72 ms |
98936 KB |
Output is correct |
12 |
Correct |
72 ms |
98936 KB |
Output is correct |
13 |
Correct |
75 ms |
98936 KB |
Output is correct |
14 |
Correct |
72 ms |
98940 KB |
Output is correct |
15 |
Correct |
90 ms |
99064 KB |
Output is correct |
16 |
Correct |
75 ms |
99448 KB |
Output is correct |
17 |
Correct |
74 ms |
99448 KB |
Output is correct |
18 |
Correct |
77 ms |
99448 KB |
Output is correct |
19 |
Correct |
91 ms |
102520 KB |
Output is correct |
20 |
Correct |
98 ms |
102520 KB |
Output is correct |
21 |
Correct |
99 ms |
102520 KB |
Output is correct |
22 |
Correct |
97 ms |
102520 KB |
Output is correct |
23 |
Correct |
106 ms |
102520 KB |
Output is correct |
24 |
Correct |
92 ms |
102520 KB |
Output is correct |
25 |
Correct |
94 ms |
102548 KB |
Output is correct |
26 |
Correct |
92 ms |
102520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1454 ms |
369408 KB |
Output is correct |
2 |
Correct |
1494 ms |
367364 KB |
Output is correct |
3 |
Correct |
1502 ms |
367344 KB |
Output is correct |
4 |
Correct |
1562 ms |
366304 KB |
Output is correct |
5 |
Correct |
1627 ms |
349868 KB |
Output is correct |
6 |
Correct |
1834 ms |
364428 KB |
Output is correct |
7 |
Correct |
1534 ms |
362440 KB |
Output is correct |
8 |
Correct |
1609 ms |
363596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
98936 KB |
Output is correct |
2 |
Correct |
757 ms |
173600 KB |
Output is correct |
3 |
Correct |
2606 ms |
365120 KB |
Output is correct |
4 |
Correct |
2527 ms |
366772 KB |
Output is correct |
5 |
Correct |
2356 ms |
359208 KB |
Output is correct |
6 |
Correct |
1067 ms |
232540 KB |
Output is correct |
7 |
Correct |
549 ms |
166060 KB |
Output is correct |
8 |
Correct |
147 ms |
112432 KB |
Output is correct |
9 |
Correct |
2487 ms |
362924 KB |
Output is correct |
10 |
Correct |
2283 ms |
364828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2434 ms |
366716 KB |
Output is correct |
2 |
Correct |
2345 ms |
365188 KB |
Output is correct |
3 |
Correct |
1809 ms |
364496 KB |
Output is correct |
4 |
Correct |
2275 ms |
364860 KB |
Output is correct |
5 |
Correct |
2699 ms |
364176 KB |
Output is correct |
6 |
Correct |
1537 ms |
363464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
98808 KB |
Output is correct |
2 |
Correct |
73 ms |
98812 KB |
Output is correct |
3 |
Correct |
72 ms |
98808 KB |
Output is correct |
4 |
Correct |
74 ms |
98864 KB |
Output is correct |
5 |
Correct |
72 ms |
98808 KB |
Output is correct |
6 |
Correct |
72 ms |
98936 KB |
Output is correct |
7 |
Correct |
73 ms |
98936 KB |
Output is correct |
8 |
Correct |
74 ms |
98936 KB |
Output is correct |
9 |
Correct |
73 ms |
98936 KB |
Output is correct |
10 |
Correct |
73 ms |
98936 KB |
Output is correct |
11 |
Correct |
72 ms |
98936 KB |
Output is correct |
12 |
Correct |
72 ms |
98936 KB |
Output is correct |
13 |
Correct |
75 ms |
98936 KB |
Output is correct |
14 |
Correct |
72 ms |
98940 KB |
Output is correct |
15 |
Correct |
90 ms |
99064 KB |
Output is correct |
16 |
Correct |
75 ms |
99448 KB |
Output is correct |
17 |
Correct |
74 ms |
99448 KB |
Output is correct |
18 |
Correct |
77 ms |
99448 KB |
Output is correct |
19 |
Correct |
91 ms |
102520 KB |
Output is correct |
20 |
Correct |
98 ms |
102520 KB |
Output is correct |
21 |
Correct |
99 ms |
102520 KB |
Output is correct |
22 |
Correct |
97 ms |
102520 KB |
Output is correct |
23 |
Correct |
106 ms |
102520 KB |
Output is correct |
24 |
Correct |
92 ms |
102520 KB |
Output is correct |
25 |
Correct |
94 ms |
102548 KB |
Output is correct |
26 |
Correct |
92 ms |
102520 KB |
Output is correct |
27 |
Correct |
104 ms |
106488 KB |
Output is correct |
28 |
Correct |
108 ms |
106488 KB |
Output is correct |
29 |
Correct |
110 ms |
106488 KB |
Output is correct |
30 |
Correct |
123 ms |
106488 KB |
Output is correct |
31 |
Correct |
112 ms |
106364 KB |
Output is correct |
32 |
Correct |
113 ms |
106360 KB |
Output is correct |
33 |
Correct |
474 ms |
173280 KB |
Output is correct |
34 |
Correct |
487 ms |
173412 KB |
Output is correct |
35 |
Correct |
488 ms |
173572 KB |
Output is correct |
36 |
Correct |
693 ms |
173280 KB |
Output is correct |
37 |
Correct |
710 ms |
173204 KB |
Output is correct |
38 |
Correct |
691 ms |
173028 KB |
Output is correct |
39 |
Correct |
507 ms |
159076 KB |
Output is correct |
40 |
Correct |
510 ms |
159196 KB |
Output is correct |
41 |
Correct |
509 ms |
159044 KB |
Output is correct |
42 |
Correct |
377 ms |
156384 KB |
Output is correct |
43 |
Correct |
538 ms |
172904 KB |
Output is correct |
44 |
Correct |
541 ms |
173028 KB |
Output is correct |
45 |
Correct |
535 ms |
172944 KB |
Output is correct |
46 |
Correct |
550 ms |
172844 KB |
Output is correct |
47 |
Correct |
545 ms |
173028 KB |
Output is correct |
48 |
Correct |
556 ms |
173044 KB |
Output is correct |
49 |
Correct |
574 ms |
172900 KB |
Output is correct |
50 |
Correct |
559 ms |
173028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
98808 KB |
Output is correct |
2 |
Correct |
73 ms |
98812 KB |
Output is correct |
3 |
Correct |
72 ms |
98808 KB |
Output is correct |
4 |
Correct |
74 ms |
98864 KB |
Output is correct |
5 |
Correct |
72 ms |
98808 KB |
Output is correct |
6 |
Correct |
72 ms |
98936 KB |
Output is correct |
7 |
Correct |
73 ms |
98936 KB |
Output is correct |
8 |
Correct |
74 ms |
98936 KB |
Output is correct |
9 |
Correct |
73 ms |
98936 KB |
Output is correct |
10 |
Correct |
73 ms |
98936 KB |
Output is correct |
11 |
Correct |
72 ms |
98936 KB |
Output is correct |
12 |
Correct |
72 ms |
98936 KB |
Output is correct |
13 |
Correct |
75 ms |
98936 KB |
Output is correct |
14 |
Correct |
72 ms |
98940 KB |
Output is correct |
15 |
Correct |
90 ms |
99064 KB |
Output is correct |
16 |
Correct |
75 ms |
99448 KB |
Output is correct |
17 |
Correct |
74 ms |
99448 KB |
Output is correct |
18 |
Correct |
77 ms |
99448 KB |
Output is correct |
19 |
Correct |
91 ms |
102520 KB |
Output is correct |
20 |
Correct |
98 ms |
102520 KB |
Output is correct |
21 |
Correct |
99 ms |
102520 KB |
Output is correct |
22 |
Correct |
97 ms |
102520 KB |
Output is correct |
23 |
Correct |
106 ms |
102520 KB |
Output is correct |
24 |
Correct |
92 ms |
102520 KB |
Output is correct |
25 |
Correct |
94 ms |
102548 KB |
Output is correct |
26 |
Correct |
92 ms |
102520 KB |
Output is correct |
27 |
Correct |
1454 ms |
369408 KB |
Output is correct |
28 |
Correct |
1494 ms |
367364 KB |
Output is correct |
29 |
Correct |
1502 ms |
367344 KB |
Output is correct |
30 |
Correct |
1562 ms |
366304 KB |
Output is correct |
31 |
Correct |
1627 ms |
349868 KB |
Output is correct |
32 |
Correct |
1834 ms |
364428 KB |
Output is correct |
33 |
Correct |
1534 ms |
362440 KB |
Output is correct |
34 |
Correct |
1609 ms |
363596 KB |
Output is correct |
35 |
Correct |
73 ms |
98936 KB |
Output is correct |
36 |
Correct |
757 ms |
173600 KB |
Output is correct |
37 |
Correct |
2606 ms |
365120 KB |
Output is correct |
38 |
Correct |
2527 ms |
366772 KB |
Output is correct |
39 |
Correct |
2356 ms |
359208 KB |
Output is correct |
40 |
Correct |
1067 ms |
232540 KB |
Output is correct |
41 |
Correct |
549 ms |
166060 KB |
Output is correct |
42 |
Correct |
147 ms |
112432 KB |
Output is correct |
43 |
Correct |
2487 ms |
362924 KB |
Output is correct |
44 |
Correct |
2283 ms |
364828 KB |
Output is correct |
45 |
Correct |
2434 ms |
366716 KB |
Output is correct |
46 |
Correct |
2345 ms |
365188 KB |
Output is correct |
47 |
Correct |
1809 ms |
364496 KB |
Output is correct |
48 |
Correct |
2275 ms |
364860 KB |
Output is correct |
49 |
Correct |
2699 ms |
364176 KB |
Output is correct |
50 |
Correct |
1537 ms |
363464 KB |
Output is correct |
51 |
Correct |
104 ms |
106488 KB |
Output is correct |
52 |
Correct |
108 ms |
106488 KB |
Output is correct |
53 |
Correct |
110 ms |
106488 KB |
Output is correct |
54 |
Correct |
123 ms |
106488 KB |
Output is correct |
55 |
Correct |
112 ms |
106364 KB |
Output is correct |
56 |
Correct |
113 ms |
106360 KB |
Output is correct |
57 |
Correct |
474 ms |
173280 KB |
Output is correct |
58 |
Correct |
487 ms |
173412 KB |
Output is correct |
59 |
Correct |
488 ms |
173572 KB |
Output is correct |
60 |
Correct |
693 ms |
173280 KB |
Output is correct |
61 |
Correct |
710 ms |
173204 KB |
Output is correct |
62 |
Correct |
691 ms |
173028 KB |
Output is correct |
63 |
Correct |
507 ms |
159076 KB |
Output is correct |
64 |
Correct |
510 ms |
159196 KB |
Output is correct |
65 |
Correct |
509 ms |
159044 KB |
Output is correct |
66 |
Correct |
377 ms |
156384 KB |
Output is correct |
67 |
Correct |
538 ms |
172904 KB |
Output is correct |
68 |
Correct |
541 ms |
173028 KB |
Output is correct |
69 |
Correct |
535 ms |
172944 KB |
Output is correct |
70 |
Correct |
550 ms |
172844 KB |
Output is correct |
71 |
Correct |
545 ms |
173028 KB |
Output is correct |
72 |
Correct |
556 ms |
173044 KB |
Output is correct |
73 |
Correct |
574 ms |
172900 KB |
Output is correct |
74 |
Correct |
559 ms |
173028 KB |
Output is correct |
75 |
Correct |
1553 ms |
366824 KB |
Output is correct |
76 |
Correct |
1604 ms |
366320 KB |
Output is correct |
77 |
Correct |
1570 ms |
365160 KB |
Output is correct |
78 |
Correct |
1515 ms |
365376 KB |
Output is correct |
79 |
Correct |
1560 ms |
364872 KB |
Output is correct |
80 |
Correct |
1539 ms |
365248 KB |
Output is correct |
81 |
Correct |
2492 ms |
364360 KB |
Output is correct |
82 |
Correct |
2359 ms |
363648 KB |
Output is correct |
83 |
Correct |
2451 ms |
363712 KB |
Output is correct |
84 |
Correct |
2546 ms |
363840 KB |
Output is correct |
85 |
Correct |
2438 ms |
363780 KB |
Output is correct |
86 |
Correct |
2635 ms |
363964 KB |
Output is correct |
87 |
Execution timed out |
3054 ms |
363528 KB |
Time limit exceeded |
88 |
Halted |
0 ms |
0 KB |
- |