#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;
struct circle
{
int x,y,r,id;
circle(int _x, int _y, int _r, int _id){x=_x;y=_y;r=_r;id=_id;}
};
bool operator<(circle a, circle b)
{
if(a.r!=b.r) return a.r<b.r;
else return a.id>b.id;
}
vector<circle> a;
int ans[333333];
vector<circle> vec;
vector<pair<int,int> > V[333333];
vi xs;
void init(int R)
{
xs.clear();
for(int i=0;i<vec.size();i++)
{
if(!ans[vec[i].id])
{
xs.pb(vec[i].x/R);
}
}
sort(xs.begin(),xs.end()); xs.erase(unique(xs.begin(),xs.end()),xs.end());
for(int i=0;i<xs.size();i++) V[i].clear();
for(int i=0;i<vec.size();i++)
{
if(!ans[vec[i].id])
{
V[lower_bound(xs.begin(),xs.end(),vec[i].x/R)-xs.begin()].pb(mp(vec[i].y/R, vec[i].id));
}
}
for(int i=0;i<xs.size();i++) sort(V[i].begin(),V[i].end());
}
bool intersect(circle x, circle y)
{
ll d = (x.x-y.x)*1LL*(x.x-y.x) + (x.y-y.y)*1LL*(x.y-y.y);
return (d<=(x.r+y.r)*1LL*(x.r+y.r));
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int n; cin>>n;
for(int i=0;i<n;i++)
{
int x,y,r; cin>>x>>y>>r;
vec.pb(circle(x,y,r,i+1));
}
a=vec;
sort(vec.rbegin(),vec.rend());
int curC = int(1e9); init(curC);
for(int i=0;i<vec.size();i++)
{
if(ans[vec[i].id]) continue;
while(vec[i].r*2<=curC)
{
curC/=2; init(curC);
}
int x=vec[i].x/curC;
x=lower_bound(xs.begin(),xs.end(),x)-xs.begin();
for(int dx=-2;dx<=2;dx++)
{
if(x+dx>=0&&x+dx<xs.size()&&abs(xs[x]-xs[x+dx])<=2)
{
auto it = lower_bound(V[x+dx].begin(),V[x+dx].end(),mp(vec[i].y/curC - 2, -1));
for(;it!=V[x+dx].end()&&it->fi<=vec[i].y/curC + 2;it++)
{
if(ans[it->se]){continue;}
if(intersect(a[it->se-1], vec[i]))
{
ans[it->se] = vec[i].id;
}
}
}
}
}
for(int i=1;i<=n;i++)
{
cout<<ans[i];
if(i+1<=n) cout<<' ';
}
cout<<'\n';
}
Compilation message
circle_selection.cpp: In function 'void init(int)':
circle_selection.cpp:41:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<vec.size();i++)
~^~~~~~~~~~~
circle_selection.cpp:49:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<xs.size();i++) V[i].clear();
~^~~~~~~~~~
circle_selection.cpp:50:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<vec.size();i++)
~^~~~~~~~~~~
circle_selection.cpp:57:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<xs.size();i++) sort(V[i].begin(),V[i].end());
~^~~~~~~~~~
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:78:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<vec.size();i++)
~^~~~~~~~~~~
circle_selection.cpp:89:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(x+dx>=0&&x+dx<xs.size()&&abs(xs[x]-xs[x+dx])<=2)
~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
8184 KB |
Output is correct |
2 |
Correct |
9 ms |
8184 KB |
Output is correct |
3 |
Correct |
10 ms |
8248 KB |
Output is correct |
4 |
Correct |
11 ms |
8248 KB |
Output is correct |
5 |
Correct |
11 ms |
8420 KB |
Output is correct |
6 |
Correct |
12 ms |
8420 KB |
Output is correct |
7 |
Correct |
11 ms |
8420 KB |
Output is correct |
8 |
Correct |
13 ms |
8420 KB |
Output is correct |
9 |
Correct |
11 ms |
8420 KB |
Output is correct |
10 |
Correct |
13 ms |
8420 KB |
Output is correct |
11 |
Correct |
13 ms |
8420 KB |
Output is correct |
12 |
Correct |
11 ms |
8420 KB |
Output is correct |
13 |
Correct |
12 ms |
8424 KB |
Output is correct |
14 |
Correct |
12 ms |
8424 KB |
Output is correct |
15 |
Correct |
14 ms |
8424 KB |
Output is correct |
16 |
Correct |
12 ms |
8672 KB |
Output is correct |
17 |
Correct |
13 ms |
8672 KB |
Output is correct |
18 |
Correct |
11 ms |
8672 KB |
Output is correct |
19 |
Correct |
15 ms |
9092 KB |
Output is correct |
20 |
Correct |
17 ms |
9244 KB |
Output is correct |
21 |
Correct |
18 ms |
9360 KB |
Output is correct |
22 |
Correct |
31 ms |
9872 KB |
Output is correct |
23 |
Correct |
29 ms |
9872 KB |
Output is correct |
24 |
Correct |
28 ms |
9872 KB |
Output is correct |
25 |
Correct |
34 ms |
9872 KB |
Output is correct |
26 |
Correct |
37 ms |
9872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
409 ms |
30736 KB |
Output is correct |
2 |
Correct |
378 ms |
30736 KB |
Output is correct |
3 |
Correct |
414 ms |
30736 KB |
Output is correct |
4 |
Correct |
282 ms |
30820 KB |
Output is correct |
5 |
Correct |
1593 ms |
46468 KB |
Output is correct |
6 |
Correct |
1890 ms |
58232 KB |
Output is correct |
7 |
Correct |
1569 ms |
58232 KB |
Output is correct |
8 |
Correct |
1842 ms |
58232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
58232 KB |
Output is correct |
2 |
Correct |
443 ms |
58232 KB |
Output is correct |
3 |
Correct |
1834 ms |
58232 KB |
Output is correct |
4 |
Correct |
1710 ms |
58232 KB |
Output is correct |
5 |
Correct |
1583 ms |
58232 KB |
Output is correct |
6 |
Correct |
684 ms |
58232 KB |
Output is correct |
7 |
Correct |
395 ms |
58232 KB |
Output is correct |
8 |
Correct |
84 ms |
58232 KB |
Output is correct |
9 |
Correct |
1727 ms |
58232 KB |
Output is correct |
10 |
Correct |
1215 ms |
58232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1697 ms |
58232 KB |
Output is correct |
2 |
Execution timed out |
3023 ms |
58572 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
8184 KB |
Output is correct |
2 |
Correct |
9 ms |
8184 KB |
Output is correct |
3 |
Correct |
10 ms |
8248 KB |
Output is correct |
4 |
Correct |
11 ms |
8248 KB |
Output is correct |
5 |
Correct |
11 ms |
8420 KB |
Output is correct |
6 |
Correct |
12 ms |
8420 KB |
Output is correct |
7 |
Correct |
11 ms |
8420 KB |
Output is correct |
8 |
Correct |
13 ms |
8420 KB |
Output is correct |
9 |
Correct |
11 ms |
8420 KB |
Output is correct |
10 |
Correct |
13 ms |
8420 KB |
Output is correct |
11 |
Correct |
13 ms |
8420 KB |
Output is correct |
12 |
Correct |
11 ms |
8420 KB |
Output is correct |
13 |
Correct |
12 ms |
8424 KB |
Output is correct |
14 |
Correct |
12 ms |
8424 KB |
Output is correct |
15 |
Correct |
14 ms |
8424 KB |
Output is correct |
16 |
Correct |
12 ms |
8672 KB |
Output is correct |
17 |
Correct |
13 ms |
8672 KB |
Output is correct |
18 |
Correct |
11 ms |
8672 KB |
Output is correct |
19 |
Correct |
15 ms |
9092 KB |
Output is correct |
20 |
Correct |
17 ms |
9244 KB |
Output is correct |
21 |
Correct |
18 ms |
9360 KB |
Output is correct |
22 |
Correct |
31 ms |
9872 KB |
Output is correct |
23 |
Correct |
29 ms |
9872 KB |
Output is correct |
24 |
Correct |
28 ms |
9872 KB |
Output is correct |
25 |
Correct |
34 ms |
9872 KB |
Output is correct |
26 |
Correct |
37 ms |
9872 KB |
Output is correct |
27 |
Correct |
22 ms |
58572 KB |
Output is correct |
28 |
Correct |
21 ms |
58572 KB |
Output is correct |
29 |
Correct |
25 ms |
58572 KB |
Output is correct |
30 |
Correct |
55 ms |
58572 KB |
Output is correct |
31 |
Correct |
62 ms |
58572 KB |
Output is correct |
32 |
Correct |
63 ms |
58572 KB |
Output is correct |
33 |
Correct |
115 ms |
58572 KB |
Output is correct |
34 |
Correct |
132 ms |
58572 KB |
Output is correct |
35 |
Correct |
146 ms |
58572 KB |
Output is correct |
36 |
Correct |
625 ms |
58572 KB |
Output is correct |
37 |
Correct |
597 ms |
58572 KB |
Output is correct |
38 |
Correct |
550 ms |
58572 KB |
Output is correct |
39 |
Correct |
656 ms |
58572 KB |
Output is correct |
40 |
Correct |
787 ms |
58572 KB |
Output is correct |
41 |
Correct |
865 ms |
58572 KB |
Output is correct |
42 |
Correct |
415 ms |
58572 KB |
Output is correct |
43 |
Correct |
724 ms |
58572 KB |
Output is correct |
44 |
Correct |
703 ms |
58572 KB |
Output is correct |
45 |
Correct |
671 ms |
58572 KB |
Output is correct |
46 |
Correct |
798 ms |
58572 KB |
Output is correct |
47 |
Correct |
701 ms |
58572 KB |
Output is correct |
48 |
Correct |
556 ms |
58572 KB |
Output is correct |
49 |
Correct |
684 ms |
58572 KB |
Output is correct |
50 |
Correct |
708 ms |
58572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
8184 KB |
Output is correct |
2 |
Correct |
9 ms |
8184 KB |
Output is correct |
3 |
Correct |
10 ms |
8248 KB |
Output is correct |
4 |
Correct |
11 ms |
8248 KB |
Output is correct |
5 |
Correct |
11 ms |
8420 KB |
Output is correct |
6 |
Correct |
12 ms |
8420 KB |
Output is correct |
7 |
Correct |
11 ms |
8420 KB |
Output is correct |
8 |
Correct |
13 ms |
8420 KB |
Output is correct |
9 |
Correct |
11 ms |
8420 KB |
Output is correct |
10 |
Correct |
13 ms |
8420 KB |
Output is correct |
11 |
Correct |
13 ms |
8420 KB |
Output is correct |
12 |
Correct |
11 ms |
8420 KB |
Output is correct |
13 |
Correct |
12 ms |
8424 KB |
Output is correct |
14 |
Correct |
12 ms |
8424 KB |
Output is correct |
15 |
Correct |
14 ms |
8424 KB |
Output is correct |
16 |
Correct |
12 ms |
8672 KB |
Output is correct |
17 |
Correct |
13 ms |
8672 KB |
Output is correct |
18 |
Correct |
11 ms |
8672 KB |
Output is correct |
19 |
Correct |
15 ms |
9092 KB |
Output is correct |
20 |
Correct |
17 ms |
9244 KB |
Output is correct |
21 |
Correct |
18 ms |
9360 KB |
Output is correct |
22 |
Correct |
31 ms |
9872 KB |
Output is correct |
23 |
Correct |
29 ms |
9872 KB |
Output is correct |
24 |
Correct |
28 ms |
9872 KB |
Output is correct |
25 |
Correct |
34 ms |
9872 KB |
Output is correct |
26 |
Correct |
37 ms |
9872 KB |
Output is correct |
27 |
Correct |
409 ms |
30736 KB |
Output is correct |
28 |
Correct |
378 ms |
30736 KB |
Output is correct |
29 |
Correct |
414 ms |
30736 KB |
Output is correct |
30 |
Correct |
282 ms |
30820 KB |
Output is correct |
31 |
Correct |
1593 ms |
46468 KB |
Output is correct |
32 |
Correct |
1890 ms |
58232 KB |
Output is correct |
33 |
Correct |
1569 ms |
58232 KB |
Output is correct |
34 |
Correct |
1842 ms |
58232 KB |
Output is correct |
35 |
Correct |
9 ms |
58232 KB |
Output is correct |
36 |
Correct |
443 ms |
58232 KB |
Output is correct |
37 |
Correct |
1834 ms |
58232 KB |
Output is correct |
38 |
Correct |
1710 ms |
58232 KB |
Output is correct |
39 |
Correct |
1583 ms |
58232 KB |
Output is correct |
40 |
Correct |
684 ms |
58232 KB |
Output is correct |
41 |
Correct |
395 ms |
58232 KB |
Output is correct |
42 |
Correct |
84 ms |
58232 KB |
Output is correct |
43 |
Correct |
1727 ms |
58232 KB |
Output is correct |
44 |
Correct |
1215 ms |
58232 KB |
Output is correct |
45 |
Correct |
1697 ms |
58232 KB |
Output is correct |
46 |
Execution timed out |
3023 ms |
58572 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |