#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define ET cout << "\n"
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cerr << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll ans[300005],x[300005],y[300005],r[300005],arr[300005],arr2[300005],rmlog,n;
vector<vector<ll>> v;
const ll C=1e9;
bool intersect(ll a,ll b)
{
return (x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b])<=(r[a]+r[b])*(r[a]+r[b]);
}
void split()
{
--rmlog;
vector<vector<ll>> tmp;
for(auto &tv:v)
{
vector<ll> sp[2];
for(auto &i:tv)
if(!ans[i])
sp[x[i]>>rmlog&1].pb(i);
if(sp[0].size()) tmp.pb(sp[0]);
if(sp[1].size()) tmp.pb(sp[1]);
}
v.swap(tmp);
}
int main()
{
cin >> n;
for(int i=1;i<=n;++i)
cin >> x[i] >> y[i] >> r[i],x[i]+=C,y[i]+=C,arr2[i]=arr[i]=i,rmlog=max(rmlog,__lg(r[i])+1);
sort(arr+1,arr+n+1,[&](ll a,ll b){return x[a]>>rmlog==x[b]>>rmlog?y[a]<y[b]:x[a]>>rmlog<x[b]>>rmlog;});
sort(arr2+1,arr2+n+1,[&](ll a,ll b){return r[a]==r[b]?a<b:r[a]>r[b];});
for(int i=1;i<=n;++i)
if(v.empty()||x[v.back()[0]]>>rmlog!=x[arr[i]]>>rmlog)
v.pb(vector<ll>(1,arr[i]));
else
v.back().pb(arr[i]);
for(int i=1;i<=n;++i)
{
int cur=arr2[i],L,R;
if(ans[cur]) continue;
while(r[cur]<<1<=1<<rmlog)
split();
for(L=0,R=v.size();L<R;)
{
int m=L+R>>1;
if((x[v[m][0]]>>rmlog)+2>=x[cur]>>rmlog) R=m;
else L=m+1;
}
for(int j=L;j<v.size()&&x[v[j][0]]>>rmlog<=(x[cur]>>rmlog)+2;++j)
{
int lf=0,ri=v[j].size();
while(lf<ri)
{
int m=lf+ri>>1;
if(y[v[j][m]]>=y[cur]-r[cur]*2) ri=m;
else lf=m+1;
}
for(int k=lf;k<v[j].size()&&y[v[j][k]]<=y[cur]+r[cur]*2;++k)
if(!ans[v[j][k]]&&intersect(v[j][k],cur))
ans[v[j][k]]=cur;
}
}
for(int i=1;i<=n;++i)
cout << ans[i] << " \n"[i==n];
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:62:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m=L+R>>1;
~^~
circle_selection.cpp:66:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=L;j<v.size()&&x[v[j][0]]>>rmlog<=(x[cur]>>rmlog)+2;++j)
~^~~~~~~~~
circle_selection.cpp:71:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m=lf+ri>>1;
~~^~~
circle_selection.cpp:75:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int k=lf;k<v[j].size()&&y[v[j][k]]<=y[cur]+r[cur]*2;++k)
~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
42 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
13 ms |
768 KB |
Output is correct |
20 |
Correct |
12 ms |
768 KB |
Output is correct |
21 |
Correct |
13 ms |
896 KB |
Output is correct |
22 |
Correct |
14 ms |
1024 KB |
Output is correct |
23 |
Correct |
13 ms |
896 KB |
Output is correct |
24 |
Correct |
14 ms |
1124 KB |
Output is correct |
25 |
Correct |
13 ms |
1152 KB |
Output is correct |
26 |
Correct |
15 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
528 ms |
18616 KB |
Output is correct |
2 |
Correct |
629 ms |
17816 KB |
Output is correct |
3 |
Correct |
516 ms |
19548 KB |
Output is correct |
4 |
Correct |
518 ms |
17384 KB |
Output is correct |
5 |
Correct |
605 ms |
20216 KB |
Output is correct |
6 |
Correct |
791 ms |
26020 KB |
Output is correct |
7 |
Correct |
449 ms |
21068 KB |
Output is correct |
8 |
Correct |
537 ms |
21332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
288 ms |
8420 KB |
Output is correct |
3 |
Correct |
1139 ms |
30440 KB |
Output is correct |
4 |
Correct |
976 ms |
30508 KB |
Output is correct |
5 |
Correct |
773 ms |
28732 KB |
Output is correct |
6 |
Correct |
367 ms |
16356 KB |
Output is correct |
7 |
Correct |
166 ms |
8824 KB |
Output is correct |
8 |
Correct |
33 ms |
2424 KB |
Output is correct |
9 |
Correct |
1195 ms |
30308 KB |
Output is correct |
10 |
Correct |
827 ms |
30400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
985 ms |
21916 KB |
Output is correct |
2 |
Correct |
1035 ms |
50268 KB |
Output is correct |
3 |
Correct |
618 ms |
18936 KB |
Output is correct |
4 |
Correct |
1041 ms |
33024 KB |
Output is correct |
5 |
Correct |
901 ms |
33044 KB |
Output is correct |
6 |
Correct |
627 ms |
18864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
42 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
13 ms |
768 KB |
Output is correct |
20 |
Correct |
12 ms |
768 KB |
Output is correct |
21 |
Correct |
13 ms |
896 KB |
Output is correct |
22 |
Correct |
14 ms |
1024 KB |
Output is correct |
23 |
Correct |
13 ms |
896 KB |
Output is correct |
24 |
Correct |
14 ms |
1124 KB |
Output is correct |
25 |
Correct |
13 ms |
1152 KB |
Output is correct |
26 |
Correct |
15 ms |
1152 KB |
Output is correct |
27 |
Correct |
20 ms |
1272 KB |
Output is correct |
28 |
Correct |
22 ms |
1272 KB |
Output is correct |
29 |
Correct |
19 ms |
1280 KB |
Output is correct |
30 |
Correct |
29 ms |
1400 KB |
Output is correct |
31 |
Correct |
24 ms |
1784 KB |
Output is correct |
32 |
Correct |
31 ms |
1792 KB |
Output is correct |
33 |
Correct |
226 ms |
9680 KB |
Output is correct |
34 |
Correct |
245 ms |
9788 KB |
Output is correct |
35 |
Correct |
199 ms |
9004 KB |
Output is correct |
36 |
Correct |
257 ms |
12924 KB |
Output is correct |
37 |
Correct |
299 ms |
12148 KB |
Output is correct |
38 |
Correct |
309 ms |
11252 KB |
Output is correct |
39 |
Correct |
275 ms |
9448 KB |
Output is correct |
40 |
Correct |
228 ms |
9444 KB |
Output is correct |
41 |
Correct |
259 ms |
9800 KB |
Output is correct |
42 |
Correct |
133 ms |
8440 KB |
Output is correct |
43 |
Correct |
205 ms |
13484 KB |
Output is correct |
44 |
Correct |
220 ms |
13600 KB |
Output is correct |
45 |
Correct |
192 ms |
13604 KB |
Output is correct |
46 |
Correct |
266 ms |
13600 KB |
Output is correct |
47 |
Correct |
251 ms |
13600 KB |
Output is correct |
48 |
Correct |
265 ms |
13732 KB |
Output is correct |
49 |
Correct |
256 ms |
13580 KB |
Output is correct |
50 |
Correct |
200 ms |
13604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
42 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
13 ms |
768 KB |
Output is correct |
20 |
Correct |
12 ms |
768 KB |
Output is correct |
21 |
Correct |
13 ms |
896 KB |
Output is correct |
22 |
Correct |
14 ms |
1024 KB |
Output is correct |
23 |
Correct |
13 ms |
896 KB |
Output is correct |
24 |
Correct |
14 ms |
1124 KB |
Output is correct |
25 |
Correct |
13 ms |
1152 KB |
Output is correct |
26 |
Correct |
15 ms |
1152 KB |
Output is correct |
27 |
Correct |
528 ms |
18616 KB |
Output is correct |
28 |
Correct |
629 ms |
17816 KB |
Output is correct |
29 |
Correct |
516 ms |
19548 KB |
Output is correct |
30 |
Correct |
518 ms |
17384 KB |
Output is correct |
31 |
Correct |
605 ms |
20216 KB |
Output is correct |
32 |
Correct |
791 ms |
26020 KB |
Output is correct |
33 |
Correct |
449 ms |
21068 KB |
Output is correct |
34 |
Correct |
537 ms |
21332 KB |
Output is correct |
35 |
Correct |
3 ms |
384 KB |
Output is correct |
36 |
Correct |
288 ms |
8420 KB |
Output is correct |
37 |
Correct |
1139 ms |
30440 KB |
Output is correct |
38 |
Correct |
976 ms |
30508 KB |
Output is correct |
39 |
Correct |
773 ms |
28732 KB |
Output is correct |
40 |
Correct |
367 ms |
16356 KB |
Output is correct |
41 |
Correct |
166 ms |
8824 KB |
Output is correct |
42 |
Correct |
33 ms |
2424 KB |
Output is correct |
43 |
Correct |
1195 ms |
30308 KB |
Output is correct |
44 |
Correct |
827 ms |
30400 KB |
Output is correct |
45 |
Correct |
985 ms |
21916 KB |
Output is correct |
46 |
Correct |
1035 ms |
50268 KB |
Output is correct |
47 |
Correct |
618 ms |
18936 KB |
Output is correct |
48 |
Correct |
1041 ms |
33024 KB |
Output is correct |
49 |
Correct |
901 ms |
33044 KB |
Output is correct |
50 |
Correct |
627 ms |
18864 KB |
Output is correct |
51 |
Correct |
20 ms |
1272 KB |
Output is correct |
52 |
Correct |
22 ms |
1272 KB |
Output is correct |
53 |
Correct |
19 ms |
1280 KB |
Output is correct |
54 |
Correct |
29 ms |
1400 KB |
Output is correct |
55 |
Correct |
24 ms |
1784 KB |
Output is correct |
56 |
Correct |
31 ms |
1792 KB |
Output is correct |
57 |
Correct |
226 ms |
9680 KB |
Output is correct |
58 |
Correct |
245 ms |
9788 KB |
Output is correct |
59 |
Correct |
199 ms |
9004 KB |
Output is correct |
60 |
Correct |
257 ms |
12924 KB |
Output is correct |
61 |
Correct |
299 ms |
12148 KB |
Output is correct |
62 |
Correct |
309 ms |
11252 KB |
Output is correct |
63 |
Correct |
275 ms |
9448 KB |
Output is correct |
64 |
Correct |
228 ms |
9444 KB |
Output is correct |
65 |
Correct |
259 ms |
9800 KB |
Output is correct |
66 |
Correct |
133 ms |
8440 KB |
Output is correct |
67 |
Correct |
205 ms |
13484 KB |
Output is correct |
68 |
Correct |
220 ms |
13600 KB |
Output is correct |
69 |
Correct |
192 ms |
13604 KB |
Output is correct |
70 |
Correct |
266 ms |
13600 KB |
Output is correct |
71 |
Correct |
251 ms |
13600 KB |
Output is correct |
72 |
Correct |
265 ms |
13732 KB |
Output is correct |
73 |
Correct |
256 ms |
13580 KB |
Output is correct |
74 |
Correct |
200 ms |
13604 KB |
Output is correct |
75 |
Correct |
714 ms |
27412 KB |
Output is correct |
76 |
Correct |
630 ms |
25736 KB |
Output is correct |
77 |
Correct |
665 ms |
28852 KB |
Output is correct |
78 |
Correct |
640 ms |
27872 KB |
Output is correct |
79 |
Correct |
636 ms |
25772 KB |
Output is correct |
80 |
Correct |
629 ms |
27868 KB |
Output is correct |
81 |
Correct |
956 ms |
31900 KB |
Output is correct |
82 |
Correct |
954 ms |
32548 KB |
Output is correct |
83 |
Correct |
1106 ms |
34716 KB |
Output is correct |
84 |
Correct |
1138 ms |
30308 KB |
Output is correct |
85 |
Correct |
1087 ms |
31732 KB |
Output is correct |
86 |
Correct |
1102 ms |
32936 KB |
Output is correct |
87 |
Correct |
1065 ms |
27512 KB |
Output is correct |
88 |
Correct |
1461 ms |
29564 KB |
Output is correct |
89 |
Correct |
1469 ms |
29748 KB |
Output is correct |
90 |
Correct |
1324 ms |
29104 KB |
Output is correct |
91 |
Correct |
1154 ms |
29152 KB |
Output is correct |
92 |
Correct |
1420 ms |
29116 KB |
Output is correct |
93 |
Correct |
934 ms |
50164 KB |
Output is correct |
94 |
Correct |
763 ms |
27016 KB |
Output is correct |
95 |
Correct |
851 ms |
51464 KB |
Output is correct |
96 |
Correct |
941 ms |
55560 KB |
Output is correct |
97 |
Correct |
843 ms |
27512 KB |
Output is correct |
98 |
Correct |
794 ms |
34008 KB |
Output is correct |
99 |
Correct |
1039 ms |
49672 KB |
Output is correct |
100 |
Correct |
1036 ms |
56840 KB |
Output is correct |
101 |
Correct |
915 ms |
30476 KB |
Output is correct |
102 |
Correct |
1042 ms |
48392 KB |
Output is correct |
103 |
Correct |
977 ms |
28104 KB |
Output is correct |
104 |
Correct |
1040 ms |
48780 KB |
Output is correct |
105 |
Correct |
488 ms |
25080 KB |
Output is correct |
106 |
Correct |
891 ms |
37024 KB |
Output is correct |
107 |
Correct |
858 ms |
37144 KB |
Output is correct |
108 |
Correct |
1002 ms |
37128 KB |
Output is correct |
109 |
Correct |
789 ms |
36996 KB |
Output is correct |
110 |
Correct |
772 ms |
37048 KB |
Output is correct |
111 |
Correct |
815 ms |
37016 KB |
Output is correct |
112 |
Correct |
883 ms |
37080 KB |
Output is correct |
113 |
Correct |
770 ms |
37092 KB |
Output is correct |
114 |
Correct |
857 ms |
36988 KB |
Output is correct |
115 |
Correct |
873 ms |
37144 KB |
Output is correct |
116 |
Correct |
981 ms |
40576 KB |
Output is correct |