#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a),_b=(b); i<=_b; ++i)
#define FORR(i,a,b) for (int i=(a),_b=(b); i>=_b; --i)
#define REP(i,b) for (int i=0,_b=(b); i<_b; ++i)
#define endl '\n'
#define sz(x) (int) x.size()
#define mod %
#define fillchar(x,y,z) memset(x,z,y)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
typedef long long int64;
typedef unsigned long long qword;
using namespace std;
const int maxn=3e5+5;
inline int64 sqr(int64 x)
{
return x*x;
}
struct Circle{
int64 x,y,r;
int id;
bool IsIntersect(const Circle &c)
{
return sqr(x-c.x)+sqr(y-c.y)<=sqr(r+c.r);
}
}cir[maxn];
bool operator <(const Circle &b,const Circle &c)
{
return mp(-b.r,b.id)<mp(-c.r,c.id);
}
vector<vector<pii> > Point;
vector<int> X;
int n;
int ans[maxn];
int main()
{
#ifdef meomeomeooooo
freopen("input.txt","r",stdin);
//freopen(".txt","w",stdout);
#endif // meomeomeooooo
iostream::sync_with_stdio(false);
cin.tie(0);
cin >> n;
set<Circle> myset;
FOR(i,1,n) {
cin >> cir[i].x >> cir[i].y >> cir[i].r;
X.push_back(cir[i].x);
cir[i].id=i;
myset.insert(cir[i]);
}
sort(X.begin(),X.end());
X.resize(unique(X.begin(),X.end())-X.begin());
#define GetDec(x) (lower_bound(X.begin(),X.end(),x)-X.begin())
Point.resize(X.size());
FOR(i,1,n) {
int x=GetDec(cir[i].x);
Point[x].push_back({cir[i].y,cir[i].id});
}
REP(i,X.size())
sort(Point[i].begin(),Point[i].end());
while (myset.size()) {
Circle cur=*myset.begin(); myset.erase(cur);
ans[cur.id]=cur.id;
int x=cur.x,y=cur.y,r=cur.r;
int Lx=max(1ll*x-2*r,-1000000000ll);
int Rx=min(1ll*x+2*r,1000000000ll);
int Ly=max(1ll*y-2*r,-1000000000ll);
int Ry=min(1ll*y+2*r,1000000000ll);
Lx=GetDec(Lx);
for (int i=Lx; i<X.size()&&X[i]<=Rx; ++i)
for (int j=lower_bound(Point[i].begin(),Point[i].end(),mp(Ly,0))-Point[i].begin(); j<Point[i].size()&&Point[i][j].fi<=Ry; ++j) {
int id=Point[i][j].se;
if (ans[id]==0&&cur.IsIntersect(cir[id])) {
ans[id]=cur.id;
myset.erase(cir[id]);
}
}
}
FOR(i,1,n)
cout << ans[i] << ' ';
return 0;
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:73:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=Lx; i<X.size()&&X[i]<=Rx; ++i)
~^~~~~~~~~
circle_selection.cpp:74:97: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=lower_bound(Point[i].begin(),Point[i].end(),mp(Ly,0))-Point[i].begin(); j<Point[i].size()&&Point[i][j].fi<=Ry; ++j) {
~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 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 |
2 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 |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
17 |
Correct |
4 ms |
512 KB |
Output is correct |
18 |
Correct |
4 ms |
512 KB |
Output is correct |
19 |
Correct |
9 ms |
1408 KB |
Output is correct |
20 |
Correct |
10 ms |
1408 KB |
Output is correct |
21 |
Correct |
11 ms |
1280 KB |
Output is correct |
22 |
Correct |
11 ms |
1392 KB |
Output is correct |
23 |
Correct |
12 ms |
1280 KB |
Output is correct |
24 |
Correct |
9 ms |
1280 KB |
Output is correct |
25 |
Correct |
9 ms |
1280 KB |
Output is correct |
26 |
Correct |
9 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1231 ms |
57800 KB |
Output is correct |
2 |
Correct |
1260 ms |
57996 KB |
Output is correct |
3 |
Correct |
1240 ms |
57616 KB |
Output is correct |
4 |
Correct |
1279 ms |
58016 KB |
Output is correct |
5 |
Correct |
862 ms |
52628 KB |
Output is correct |
6 |
Correct |
912 ms |
57672 KB |
Output is correct |
7 |
Correct |
949 ms |
56468 KB |
Output is correct |
8 |
Correct |
980 ms |
57060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
391 ms |
20948 KB |
Output is correct |
3 |
Correct |
1421 ms |
57192 KB |
Output is correct |
4 |
Correct |
1387 ms |
62200 KB |
Output is correct |
5 |
Correct |
2098 ms |
60612 KB |
Output is correct |
6 |
Correct |
807 ms |
32612 KB |
Output is correct |
7 |
Correct |
261 ms |
17392 KB |
Output is correct |
8 |
Correct |
28 ms |
3840 KB |
Output is correct |
9 |
Correct |
1504 ms |
62300 KB |
Output is correct |
10 |
Execution timed out |
3023 ms |
60516 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
817 ms |
57320 KB |
Output is correct |
2 |
Correct |
517 ms |
61000 KB |
Output is correct |
3 |
Correct |
2541 ms |
61960 KB |
Output is correct |
4 |
Correct |
604 ms |
61512 KB |
Output is correct |
5 |
Correct |
529 ms |
61668 KB |
Output is correct |
6 |
Execution timed out |
3101 ms |
61852 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 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 |
2 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 |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
17 |
Correct |
4 ms |
512 KB |
Output is correct |
18 |
Correct |
4 ms |
512 KB |
Output is correct |
19 |
Correct |
9 ms |
1408 KB |
Output is correct |
20 |
Correct |
10 ms |
1408 KB |
Output is correct |
21 |
Correct |
11 ms |
1280 KB |
Output is correct |
22 |
Correct |
11 ms |
1392 KB |
Output is correct |
23 |
Correct |
12 ms |
1280 KB |
Output is correct |
24 |
Correct |
9 ms |
1280 KB |
Output is correct |
25 |
Correct |
9 ms |
1280 KB |
Output is correct |
26 |
Correct |
9 ms |
1280 KB |
Output is correct |
27 |
Correct |
17 ms |
2432 KB |
Output is correct |
28 |
Correct |
21 ms |
2424 KB |
Output is correct |
29 |
Correct |
19 ms |
2424 KB |
Output is correct |
30 |
Correct |
22 ms |
2304 KB |
Output is correct |
31 |
Correct |
20 ms |
2304 KB |
Output is correct |
32 |
Correct |
23 ms |
2432 KB |
Output is correct |
33 |
Correct |
338 ms |
21332 KB |
Output is correct |
34 |
Correct |
318 ms |
21360 KB |
Output is correct |
35 |
Correct |
384 ms |
21104 KB |
Output is correct |
36 |
Correct |
281 ms |
20724 KB |
Output is correct |
37 |
Correct |
286 ms |
20908 KB |
Output is correct |
38 |
Correct |
325 ms |
20844 KB |
Output is correct |
39 |
Correct |
242 ms |
14920 KB |
Output is correct |
40 |
Correct |
346 ms |
15024 KB |
Output is correct |
41 |
Correct |
295 ms |
14940 KB |
Output is correct |
42 |
Correct |
203 ms |
15472 KB |
Output is correct |
43 |
Correct |
222 ms |
20720 KB |
Output is correct |
44 |
Correct |
185 ms |
20848 KB |
Output is correct |
45 |
Correct |
178 ms |
20800 KB |
Output is correct |
46 |
Correct |
189 ms |
20796 KB |
Output is correct |
47 |
Correct |
157 ms |
20720 KB |
Output is correct |
48 |
Correct |
166 ms |
20800 KB |
Output is correct |
49 |
Correct |
165 ms |
20712 KB |
Output is correct |
50 |
Correct |
156 ms |
20720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 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 |
2 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 |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
17 |
Correct |
4 ms |
512 KB |
Output is correct |
18 |
Correct |
4 ms |
512 KB |
Output is correct |
19 |
Correct |
9 ms |
1408 KB |
Output is correct |
20 |
Correct |
10 ms |
1408 KB |
Output is correct |
21 |
Correct |
11 ms |
1280 KB |
Output is correct |
22 |
Correct |
11 ms |
1392 KB |
Output is correct |
23 |
Correct |
12 ms |
1280 KB |
Output is correct |
24 |
Correct |
9 ms |
1280 KB |
Output is correct |
25 |
Correct |
9 ms |
1280 KB |
Output is correct |
26 |
Correct |
9 ms |
1280 KB |
Output is correct |
27 |
Correct |
1231 ms |
57800 KB |
Output is correct |
28 |
Correct |
1260 ms |
57996 KB |
Output is correct |
29 |
Correct |
1240 ms |
57616 KB |
Output is correct |
30 |
Correct |
1279 ms |
58016 KB |
Output is correct |
31 |
Correct |
862 ms |
52628 KB |
Output is correct |
32 |
Correct |
912 ms |
57672 KB |
Output is correct |
33 |
Correct |
949 ms |
56468 KB |
Output is correct |
34 |
Correct |
980 ms |
57060 KB |
Output is correct |
35 |
Correct |
3 ms |
384 KB |
Output is correct |
36 |
Correct |
391 ms |
20948 KB |
Output is correct |
37 |
Correct |
1421 ms |
57192 KB |
Output is correct |
38 |
Correct |
1387 ms |
62200 KB |
Output is correct |
39 |
Correct |
2098 ms |
60612 KB |
Output is correct |
40 |
Correct |
807 ms |
32612 KB |
Output is correct |
41 |
Correct |
261 ms |
17392 KB |
Output is correct |
42 |
Correct |
28 ms |
3840 KB |
Output is correct |
43 |
Correct |
1504 ms |
62300 KB |
Output is correct |
44 |
Execution timed out |
3023 ms |
60516 KB |
Time limit exceeded |