#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
struct circle{ ll x,y,r;int id;circle(){}circle(ll a, ll b, ll c):x(a),y(b),r(c){}};
ll sq(ll x){ return x*x;}
bool sec(circle a, circle b){ return sq(a.x-b.x)+sq(a.y-b.y)<=sq(a.r+b.r);}
bool operator < (circle a, circle b){ return a.r<b.r;}
const int N=300050;
const ll mul=2e9+7;
circle a[N];
int ans[N];
unordered_map<ll,int> id;
vector<pair<int,circle>> all[N];
int main()
{
int n,i;
scanf("%i",&n);
for(i=1;i<=n;i++) scanf("%lld %lld %lld",&a[i].x,&a[i].y,&a[i].r),a[i].id=i;
sort(a+1,a+1+n,[](circle a, circle b){ return a.r>b.r || a.r==b.r && a.id<b.id;});
for(int j=30;j>=0;j--)
{
int po=1<<j;
id.clear();
int cnt=0;
for(i=1;i<=n;i++) if(!ans[a[i].id])
{
pair<int,int> pa=mp(floor((double)a[i].x/po),floor((double)a[i].y/po));
ll p=pa.first;
if(!id[p]) id[p]=++cnt,all[cnt].clear();
all[id[p]].pb(mp(pa.second,a[i]));
}
for(i=1;i<=cnt;i++) sort(all[i].begin(),all[i].end());
for(i=1;i<=n;i++) if(!ans[a[i].id] && a[i].r>=(1<<j-1))
{
int x=floor((double)a[i].x/po);
int y=floor((double)a[i].y/po);
for(int l=-2;l<=2;l++)
{
ll p=x+l;
if(!id.count(p)) continue;
int idx=id[p];
int lb=upper_bound(all[idx].begin(),all[idx].end(),mp(y-3,a[i]))-all[idx].begin();
int rb=upper_bound(all[idx].begin(),all[idx].end(),mp(y+2,a[i]))-all[idx].begin();
for(int r=lb;r<rb;r++)
{
circle c=all[idx][r].second;
if(!ans[c.id] && sec(c,a[i])) ans[c.id]=a[i].id;
}
}
}
}
for(i=1;i<=n;i++) printf("%i%c",ans[i],i==n?'\n':' ');
return 0;
}
Compilation message
circle_selection.cpp: In lambda function:
circle_selection.cpp:21:68: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
sort(a+1,a+1+n,[](circle a, circle b){ return a.r>b.r || a.r==b.r && a.id<b.id;});
~~~~~~~~~^~~~~~~~~~~~
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:35:54: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
for(i=1;i<=n;i++) if(!ans[a[i].id] && a[i].r>=(1<<j-1))
~^~
circle_selection.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i",&n);
~~~~~^~~~~~~~~
circle_selection.cpp:20:67: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=1;i<=n;i++) scanf("%lld %lld %lld",&a[i].x,&a[i].y,&a[i].r),a[i].id=i;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7424 KB |
Output is correct |
3 |
Correct |
9 ms |
7524 KB |
Output is correct |
4 |
Correct |
9 ms |
7424 KB |
Output is correct |
5 |
Correct |
10 ms |
7424 KB |
Output is correct |
6 |
Correct |
9 ms |
7424 KB |
Output is correct |
7 |
Correct |
8 ms |
7424 KB |
Output is correct |
8 |
Correct |
10 ms |
7440 KB |
Output is correct |
9 |
Correct |
8 ms |
7552 KB |
Output is correct |
10 |
Correct |
9 ms |
7424 KB |
Output is correct |
11 |
Correct |
9 ms |
7424 KB |
Output is correct |
12 |
Correct |
9 ms |
7424 KB |
Output is correct |
13 |
Correct |
9 ms |
7424 KB |
Output is correct |
14 |
Correct |
9 ms |
7424 KB |
Output is correct |
15 |
Correct |
11 ms |
7424 KB |
Output is correct |
16 |
Correct |
9 ms |
7424 KB |
Output is correct |
17 |
Correct |
9 ms |
7552 KB |
Output is correct |
18 |
Correct |
9 ms |
7424 KB |
Output is correct |
19 |
Correct |
13 ms |
8160 KB |
Output is correct |
20 |
Correct |
13 ms |
8032 KB |
Output is correct |
21 |
Correct |
16 ms |
8032 KB |
Output is correct |
22 |
Correct |
25 ms |
9276 KB |
Output is correct |
23 |
Correct |
27 ms |
9012 KB |
Output is correct |
24 |
Correct |
25 ms |
9404 KB |
Output is correct |
25 |
Correct |
27 ms |
9464 KB |
Output is correct |
26 |
Correct |
26 ms |
9396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
394 ms |
32068 KB |
Output is correct |
2 |
Correct |
481 ms |
45084 KB |
Output is correct |
3 |
Correct |
424 ms |
38892 KB |
Output is correct |
4 |
Correct |
314 ms |
36952 KB |
Output is correct |
5 |
Correct |
1217 ms |
114292 KB |
Output is correct |
6 |
Correct |
2019 ms |
167604 KB |
Output is correct |
7 |
Correct |
1067 ms |
126632 KB |
Output is correct |
8 |
Correct |
1509 ms |
157236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7424 KB |
Output is correct |
2 |
Correct |
506 ms |
44288 KB |
Output is correct |
3 |
Correct |
1860 ms |
143272 KB |
Output is correct |
4 |
Correct |
1692 ms |
150844 KB |
Output is correct |
5 |
Correct |
1496 ms |
129512 KB |
Output is correct |
6 |
Correct |
625 ms |
71672 KB |
Output is correct |
7 |
Correct |
287 ms |
41912 KB |
Output is correct |
8 |
Correct |
80 ms |
14604 KB |
Output is correct |
9 |
Correct |
1864 ms |
140696 KB |
Output is correct |
10 |
Correct |
1316 ms |
112596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2372 ms |
141316 KB |
Output is correct |
2 |
Execution timed out |
3034 ms |
174032 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7424 KB |
Output is correct |
3 |
Correct |
9 ms |
7524 KB |
Output is correct |
4 |
Correct |
9 ms |
7424 KB |
Output is correct |
5 |
Correct |
10 ms |
7424 KB |
Output is correct |
6 |
Correct |
9 ms |
7424 KB |
Output is correct |
7 |
Correct |
8 ms |
7424 KB |
Output is correct |
8 |
Correct |
10 ms |
7440 KB |
Output is correct |
9 |
Correct |
8 ms |
7552 KB |
Output is correct |
10 |
Correct |
9 ms |
7424 KB |
Output is correct |
11 |
Correct |
9 ms |
7424 KB |
Output is correct |
12 |
Correct |
9 ms |
7424 KB |
Output is correct |
13 |
Correct |
9 ms |
7424 KB |
Output is correct |
14 |
Correct |
9 ms |
7424 KB |
Output is correct |
15 |
Correct |
11 ms |
7424 KB |
Output is correct |
16 |
Correct |
9 ms |
7424 KB |
Output is correct |
17 |
Correct |
9 ms |
7552 KB |
Output is correct |
18 |
Correct |
9 ms |
7424 KB |
Output is correct |
19 |
Correct |
13 ms |
8160 KB |
Output is correct |
20 |
Correct |
13 ms |
8032 KB |
Output is correct |
21 |
Correct |
16 ms |
8032 KB |
Output is correct |
22 |
Correct |
25 ms |
9276 KB |
Output is correct |
23 |
Correct |
27 ms |
9012 KB |
Output is correct |
24 |
Correct |
25 ms |
9404 KB |
Output is correct |
25 |
Correct |
27 ms |
9464 KB |
Output is correct |
26 |
Correct |
26 ms |
9396 KB |
Output is correct |
27 |
Correct |
17 ms |
8508 KB |
Output is correct |
28 |
Correct |
18 ms |
8508 KB |
Output is correct |
29 |
Correct |
18 ms |
8508 KB |
Output is correct |
30 |
Correct |
49 ms |
10736 KB |
Output is correct |
31 |
Correct |
44 ms |
11720 KB |
Output is correct |
32 |
Correct |
44 ms |
11376 KB |
Output is correct |
33 |
Correct |
110 ms |
15724 KB |
Output is correct |
34 |
Correct |
105 ms |
15720 KB |
Output is correct |
35 |
Correct |
148 ms |
18520 KB |
Output is correct |
36 |
Correct |
616 ms |
56164 KB |
Output is correct |
37 |
Correct |
625 ms |
53912 KB |
Output is correct |
38 |
Correct |
499 ms |
49212 KB |
Output is correct |
39 |
Correct |
555 ms |
34288 KB |
Output is correct |
40 |
Correct |
500 ms |
35624 KB |
Output is correct |
41 |
Correct |
420 ms |
33788 KB |
Output is correct |
42 |
Correct |
355 ms |
33404 KB |
Output is correct |
43 |
Correct |
711 ms |
61060 KB |
Output is correct |
44 |
Correct |
765 ms |
62384 KB |
Output is correct |
45 |
Correct |
753 ms |
60612 KB |
Output is correct |
46 |
Correct |
723 ms |
61116 KB |
Output is correct |
47 |
Correct |
787 ms |
61148 KB |
Output is correct |
48 |
Correct |
751 ms |
61856 KB |
Output is correct |
49 |
Correct |
745 ms |
61820 KB |
Output is correct |
50 |
Correct |
770 ms |
60616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7424 KB |
Output is correct |
3 |
Correct |
9 ms |
7524 KB |
Output is correct |
4 |
Correct |
9 ms |
7424 KB |
Output is correct |
5 |
Correct |
10 ms |
7424 KB |
Output is correct |
6 |
Correct |
9 ms |
7424 KB |
Output is correct |
7 |
Correct |
8 ms |
7424 KB |
Output is correct |
8 |
Correct |
10 ms |
7440 KB |
Output is correct |
9 |
Correct |
8 ms |
7552 KB |
Output is correct |
10 |
Correct |
9 ms |
7424 KB |
Output is correct |
11 |
Correct |
9 ms |
7424 KB |
Output is correct |
12 |
Correct |
9 ms |
7424 KB |
Output is correct |
13 |
Correct |
9 ms |
7424 KB |
Output is correct |
14 |
Correct |
9 ms |
7424 KB |
Output is correct |
15 |
Correct |
11 ms |
7424 KB |
Output is correct |
16 |
Correct |
9 ms |
7424 KB |
Output is correct |
17 |
Correct |
9 ms |
7552 KB |
Output is correct |
18 |
Correct |
9 ms |
7424 KB |
Output is correct |
19 |
Correct |
13 ms |
8160 KB |
Output is correct |
20 |
Correct |
13 ms |
8032 KB |
Output is correct |
21 |
Correct |
16 ms |
8032 KB |
Output is correct |
22 |
Correct |
25 ms |
9276 KB |
Output is correct |
23 |
Correct |
27 ms |
9012 KB |
Output is correct |
24 |
Correct |
25 ms |
9404 KB |
Output is correct |
25 |
Correct |
27 ms |
9464 KB |
Output is correct |
26 |
Correct |
26 ms |
9396 KB |
Output is correct |
27 |
Correct |
394 ms |
32068 KB |
Output is correct |
28 |
Correct |
481 ms |
45084 KB |
Output is correct |
29 |
Correct |
424 ms |
38892 KB |
Output is correct |
30 |
Correct |
314 ms |
36952 KB |
Output is correct |
31 |
Correct |
1217 ms |
114292 KB |
Output is correct |
32 |
Correct |
2019 ms |
167604 KB |
Output is correct |
33 |
Correct |
1067 ms |
126632 KB |
Output is correct |
34 |
Correct |
1509 ms |
157236 KB |
Output is correct |
35 |
Correct |
8 ms |
7424 KB |
Output is correct |
36 |
Correct |
506 ms |
44288 KB |
Output is correct |
37 |
Correct |
1860 ms |
143272 KB |
Output is correct |
38 |
Correct |
1692 ms |
150844 KB |
Output is correct |
39 |
Correct |
1496 ms |
129512 KB |
Output is correct |
40 |
Correct |
625 ms |
71672 KB |
Output is correct |
41 |
Correct |
287 ms |
41912 KB |
Output is correct |
42 |
Correct |
80 ms |
14604 KB |
Output is correct |
43 |
Correct |
1864 ms |
140696 KB |
Output is correct |
44 |
Correct |
1316 ms |
112596 KB |
Output is correct |
45 |
Correct |
2372 ms |
141316 KB |
Output is correct |
46 |
Execution timed out |
3034 ms |
174032 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |