#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;
}
int ans[333333];
vector<circle> vec;
map<ii,vector<circle> > ma;
void init(int R)
{
ma.clear();
for(int i=0;i<vec.size();i++)
{
if(!ans[vec[i].id])
{
ma[mp(vec[i].x/R, vec[i].y/R)].pb(vec[i]);
}
}
}
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));
}
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; int y=vec[i].y/curC;
for(int dx=-2;dx<=2;dx++)
{
for(int dy=-2;dy<=2;dy++)
{
int x2=x+dx; int y2=y+dy;
if(ma.find(mp(x2,y2))==ma.end()) continue;
for(auto it = ma[mp(x2,y2)].begin(); it != ma[mp(x2,y2)].end();)
{
if(intersect(*it, vec[i]))
{
ans[it->id] = vec[i].id;
it = ma[mp(x2,y2)].erase(it);
}
else
{
it++;
}
}
}
}
}
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:38:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<vec.size();i++)
~^~~~~~~~~~~
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:64:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<vec.size();i++)
~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
448 KB |
Output is correct |
3 |
Correct |
2 ms |
496 KB |
Output is correct |
4 |
Correct |
3 ms |
496 KB |
Output is correct |
5 |
Correct |
3 ms |
640 KB |
Output is correct |
6 |
Correct |
4 ms |
640 KB |
Output is correct |
7 |
Correct |
2 ms |
696 KB |
Output is correct |
8 |
Correct |
3 ms |
748 KB |
Output is correct |
9 |
Correct |
3 ms |
748 KB |
Output is correct |
10 |
Correct |
2 ms |
832 KB |
Output is correct |
11 |
Correct |
3 ms |
832 KB |
Output is correct |
12 |
Correct |
4 ms |
832 KB |
Output is correct |
13 |
Correct |
3 ms |
832 KB |
Output is correct |
14 |
Correct |
3 ms |
832 KB |
Output is correct |
15 |
Correct |
3 ms |
832 KB |
Output is correct |
16 |
Correct |
4 ms |
832 KB |
Output is correct |
17 |
Correct |
6 ms |
832 KB |
Output is correct |
18 |
Correct |
4 ms |
832 KB |
Output is correct |
19 |
Correct |
17 ms |
1244 KB |
Output is correct |
20 |
Correct |
19 ms |
1404 KB |
Output is correct |
21 |
Correct |
19 ms |
1704 KB |
Output is correct |
22 |
Correct |
50 ms |
2172 KB |
Output is correct |
23 |
Correct |
46 ms |
2316 KB |
Output is correct |
24 |
Correct |
40 ms |
2424 KB |
Output is correct |
25 |
Correct |
52 ms |
2564 KB |
Output is correct |
26 |
Correct |
42 ms |
2824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3019 ms |
20936 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
20936 KB |
Output is correct |
2 |
Correct |
1825 ms |
20936 KB |
Output is correct |
3 |
Execution timed out |
3044 ms |
51156 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3015 ms |
51156 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
448 KB |
Output is correct |
3 |
Correct |
2 ms |
496 KB |
Output is correct |
4 |
Correct |
3 ms |
496 KB |
Output is correct |
5 |
Correct |
3 ms |
640 KB |
Output is correct |
6 |
Correct |
4 ms |
640 KB |
Output is correct |
7 |
Correct |
2 ms |
696 KB |
Output is correct |
8 |
Correct |
3 ms |
748 KB |
Output is correct |
9 |
Correct |
3 ms |
748 KB |
Output is correct |
10 |
Correct |
2 ms |
832 KB |
Output is correct |
11 |
Correct |
3 ms |
832 KB |
Output is correct |
12 |
Correct |
4 ms |
832 KB |
Output is correct |
13 |
Correct |
3 ms |
832 KB |
Output is correct |
14 |
Correct |
3 ms |
832 KB |
Output is correct |
15 |
Correct |
3 ms |
832 KB |
Output is correct |
16 |
Correct |
4 ms |
832 KB |
Output is correct |
17 |
Correct |
6 ms |
832 KB |
Output is correct |
18 |
Correct |
4 ms |
832 KB |
Output is correct |
19 |
Correct |
17 ms |
1244 KB |
Output is correct |
20 |
Correct |
19 ms |
1404 KB |
Output is correct |
21 |
Correct |
19 ms |
1704 KB |
Output is correct |
22 |
Correct |
50 ms |
2172 KB |
Output is correct |
23 |
Correct |
46 ms |
2316 KB |
Output is correct |
24 |
Correct |
40 ms |
2424 KB |
Output is correct |
25 |
Correct |
52 ms |
2564 KB |
Output is correct |
26 |
Correct |
42 ms |
2824 KB |
Output is correct |
27 |
Correct |
49 ms |
51156 KB |
Output is correct |
28 |
Correct |
35 ms |
51156 KB |
Output is correct |
29 |
Correct |
33 ms |
51156 KB |
Output is correct |
30 |
Correct |
93 ms |
51156 KB |
Output is correct |
31 |
Correct |
82 ms |
51156 KB |
Output is correct |
32 |
Correct |
78 ms |
51156 KB |
Output is correct |
33 |
Execution timed out |
3017 ms |
51156 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
448 KB |
Output is correct |
3 |
Correct |
2 ms |
496 KB |
Output is correct |
4 |
Correct |
3 ms |
496 KB |
Output is correct |
5 |
Correct |
3 ms |
640 KB |
Output is correct |
6 |
Correct |
4 ms |
640 KB |
Output is correct |
7 |
Correct |
2 ms |
696 KB |
Output is correct |
8 |
Correct |
3 ms |
748 KB |
Output is correct |
9 |
Correct |
3 ms |
748 KB |
Output is correct |
10 |
Correct |
2 ms |
832 KB |
Output is correct |
11 |
Correct |
3 ms |
832 KB |
Output is correct |
12 |
Correct |
4 ms |
832 KB |
Output is correct |
13 |
Correct |
3 ms |
832 KB |
Output is correct |
14 |
Correct |
3 ms |
832 KB |
Output is correct |
15 |
Correct |
3 ms |
832 KB |
Output is correct |
16 |
Correct |
4 ms |
832 KB |
Output is correct |
17 |
Correct |
6 ms |
832 KB |
Output is correct |
18 |
Correct |
4 ms |
832 KB |
Output is correct |
19 |
Correct |
17 ms |
1244 KB |
Output is correct |
20 |
Correct |
19 ms |
1404 KB |
Output is correct |
21 |
Correct |
19 ms |
1704 KB |
Output is correct |
22 |
Correct |
50 ms |
2172 KB |
Output is correct |
23 |
Correct |
46 ms |
2316 KB |
Output is correct |
24 |
Correct |
40 ms |
2424 KB |
Output is correct |
25 |
Correct |
52 ms |
2564 KB |
Output is correct |
26 |
Correct |
42 ms |
2824 KB |
Output is correct |
27 |
Execution timed out |
3019 ms |
20936 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |