#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define ll long long
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, n) for(int i = 0; i < n; ++i)
using namespace std;
const int INF = 2e9;
struct circle {
int x, y, r;
};
bool inter(circle &a, circle &b) {
return 1ll * (a.x - b.x) * (a.x - b.x) + 1ll * (a.y - b.y) * (a.y - b.y) <= 1ll * (a.r + b.r) * (a.r + b.r);
}
struct gao {
int X, Y, ID;
gao(int X, int Y, int ID) : X(X), Y(Y), ID(ID) {}
bool operator < (gao a) {
return mp(X, Y) < mp(a.X, a.Y);
}
};
vector <gao> V;
int n;
circle t[300005];
int cur = INF;
vector <int> v;
int ans[300005];
void go() {
V.clear();
for(int i = 1; i <= n; ++i) {
if(ans[i]) continue;
V.pb({t[i].x / cur, t[i].y / cur, i});
}
sort(V.begin(), V.end());
}
vector <int> wywal;
inline void solve(const int &x, const int &y, const int &id) {
auto it = lower_bound(V.begin(), V.end(), gao(x, y, -1));
while(it != V.end() && it->X == x && it->Y == y) {
if(ans[it->ID]) {
it++;
continue;
}
//cat(id);
//cat(it->ID);
if(inter(t[id], t[it->ID]))
ans[it->ID] = id;
it++;
}
}
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
scanf("%d %d %d", &t[i].x, &t[i].y, &t[i].r);
t[i].x += 1000000000;
t[i].y += 1000000000;
v.pb(i);
}
sort(v.begin(), v.end(), [](int a, int b) {
if(t[a].r != t[b].r)
return t[a].r < t[b].r;
return a > b;
});
go();
for(int i = n - 1; 0 <= i; --i) {
int ja = v[i];
if(!ans[ja]) {
if(2 * t[ja].r < cur) {
cur = t[ja].r;
go();
}
for(int x = t[ja].x / cur - 2; x <= t[ja].x / cur + 2; ++x)
for(int y = t[ja].y / cur - 2; y <= t[ja].y / cur + 2; ++y)
solve(x, y, ja);
}
}
for(int i = 1; i <= n; ++i)
printf("%d ", ans[i]);
return 0;
}
/* 11
9 9 2
13 2 1
11 8 2
3 3 2
3 12 1
12 14 1
9 8 5
2 8 2
5 2 1
14 4 2
14 14 1
*/
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:65:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
circle_selection.cpp:67:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &t[i].x, &t[i].y, &t[i].r);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
248 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
372 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
632 KB |
Output is correct |
20 |
Correct |
6 ms |
632 KB |
Output is correct |
21 |
Correct |
6 ms |
628 KB |
Output is correct |
22 |
Correct |
15 ms |
632 KB |
Output is correct |
23 |
Correct |
15 ms |
636 KB |
Output is correct |
24 |
Correct |
15 ms |
604 KB |
Output is correct |
25 |
Correct |
14 ms |
760 KB |
Output is correct |
26 |
Correct |
14 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
245 ms |
13400 KB |
Output is correct |
2 |
Correct |
248 ms |
13388 KB |
Output is correct |
3 |
Correct |
248 ms |
13148 KB |
Output is correct |
4 |
Correct |
245 ms |
13396 KB |
Output is correct |
5 |
Correct |
253 ms |
13280 KB |
Output is correct |
6 |
Correct |
505 ms |
13272 KB |
Output is correct |
7 |
Correct |
274 ms |
13272 KB |
Output is correct |
8 |
Correct |
315 ms |
13268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
252 KB |
Output is correct |
2 |
Correct |
337 ms |
4496 KB |
Output is correct |
3 |
Correct |
1106 ms |
13364 KB |
Output is correct |
4 |
Correct |
1096 ms |
21404 KB |
Output is correct |
5 |
Correct |
940 ms |
21168 KB |
Output is correct |
6 |
Correct |
379 ms |
11312 KB |
Output is correct |
7 |
Correct |
197 ms |
6044 KB |
Output is correct |
8 |
Correct |
35 ms |
1644 KB |
Output is correct |
9 |
Correct |
1111 ms |
21456 KB |
Output is correct |
10 |
Correct |
801 ms |
21720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1000 ms |
13444 KB |
Output is correct |
2 |
Correct |
846 ms |
20408 KB |
Output is correct |
3 |
Correct |
314 ms |
21212 KB |
Output is correct |
4 |
Correct |
884 ms |
20780 KB |
Output is correct |
5 |
Correct |
871 ms |
21080 KB |
Output is correct |
6 |
Correct |
264 ms |
21372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
248 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
372 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
632 KB |
Output is correct |
20 |
Correct |
6 ms |
632 KB |
Output is correct |
21 |
Correct |
6 ms |
628 KB |
Output is correct |
22 |
Correct |
15 ms |
632 KB |
Output is correct |
23 |
Correct |
15 ms |
636 KB |
Output is correct |
24 |
Correct |
15 ms |
604 KB |
Output is correct |
25 |
Correct |
14 ms |
760 KB |
Output is correct |
26 |
Correct |
14 ms |
632 KB |
Output is correct |
27 |
Correct |
10 ms |
872 KB |
Output is correct |
28 |
Correct |
10 ms |
876 KB |
Output is correct |
29 |
Correct |
10 ms |
1000 KB |
Output is correct |
30 |
Correct |
30 ms |
872 KB |
Output is correct |
31 |
Correct |
28 ms |
1000 KB |
Output is correct |
32 |
Correct |
29 ms |
872 KB |
Output is correct |
33 |
Correct |
87 ms |
4456 KB |
Output is correct |
34 |
Correct |
89 ms |
4592 KB |
Output is correct |
35 |
Correct |
93 ms |
4420 KB |
Output is correct |
36 |
Correct |
321 ms |
4448 KB |
Output is correct |
37 |
Correct |
320 ms |
4420 KB |
Output is correct |
38 |
Correct |
325 ms |
4456 KB |
Output is correct |
39 |
Correct |
279 ms |
4456 KB |
Output is correct |
40 |
Correct |
270 ms |
4412 KB |
Output is correct |
41 |
Correct |
269 ms |
4580 KB |
Output is correct |
42 |
Correct |
137 ms |
4328 KB |
Output is correct |
43 |
Correct |
240 ms |
4460 KB |
Output is correct |
44 |
Correct |
236 ms |
4460 KB |
Output is correct |
45 |
Correct |
236 ms |
4456 KB |
Output is correct |
46 |
Correct |
236 ms |
4456 KB |
Output is correct |
47 |
Correct |
236 ms |
4440 KB |
Output is correct |
48 |
Correct |
237 ms |
4456 KB |
Output is correct |
49 |
Correct |
237 ms |
4516 KB |
Output is correct |
50 |
Correct |
236 ms |
4480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
248 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
372 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
632 KB |
Output is correct |
20 |
Correct |
6 ms |
632 KB |
Output is correct |
21 |
Correct |
6 ms |
628 KB |
Output is correct |
22 |
Correct |
15 ms |
632 KB |
Output is correct |
23 |
Correct |
15 ms |
636 KB |
Output is correct |
24 |
Correct |
15 ms |
604 KB |
Output is correct |
25 |
Correct |
14 ms |
760 KB |
Output is correct |
26 |
Correct |
14 ms |
632 KB |
Output is correct |
27 |
Correct |
245 ms |
13400 KB |
Output is correct |
28 |
Correct |
248 ms |
13388 KB |
Output is correct |
29 |
Correct |
248 ms |
13148 KB |
Output is correct |
30 |
Correct |
245 ms |
13396 KB |
Output is correct |
31 |
Correct |
253 ms |
13280 KB |
Output is correct |
32 |
Correct |
505 ms |
13272 KB |
Output is correct |
33 |
Correct |
274 ms |
13272 KB |
Output is correct |
34 |
Correct |
315 ms |
13268 KB |
Output is correct |
35 |
Correct |
2 ms |
252 KB |
Output is correct |
36 |
Correct |
337 ms |
4496 KB |
Output is correct |
37 |
Correct |
1106 ms |
13364 KB |
Output is correct |
38 |
Correct |
1096 ms |
21404 KB |
Output is correct |
39 |
Correct |
940 ms |
21168 KB |
Output is correct |
40 |
Correct |
379 ms |
11312 KB |
Output is correct |
41 |
Correct |
197 ms |
6044 KB |
Output is correct |
42 |
Correct |
35 ms |
1644 KB |
Output is correct |
43 |
Correct |
1111 ms |
21456 KB |
Output is correct |
44 |
Correct |
801 ms |
21720 KB |
Output is correct |
45 |
Correct |
1000 ms |
13444 KB |
Output is correct |
46 |
Correct |
846 ms |
20408 KB |
Output is correct |
47 |
Correct |
314 ms |
21212 KB |
Output is correct |
48 |
Correct |
884 ms |
20780 KB |
Output is correct |
49 |
Correct |
871 ms |
21080 KB |
Output is correct |
50 |
Correct |
264 ms |
21372 KB |
Output is correct |
51 |
Correct |
10 ms |
872 KB |
Output is correct |
52 |
Correct |
10 ms |
876 KB |
Output is correct |
53 |
Correct |
10 ms |
1000 KB |
Output is correct |
54 |
Correct |
30 ms |
872 KB |
Output is correct |
55 |
Correct |
28 ms |
1000 KB |
Output is correct |
56 |
Correct |
29 ms |
872 KB |
Output is correct |
57 |
Correct |
87 ms |
4456 KB |
Output is correct |
58 |
Correct |
89 ms |
4592 KB |
Output is correct |
59 |
Correct |
93 ms |
4420 KB |
Output is correct |
60 |
Correct |
321 ms |
4448 KB |
Output is correct |
61 |
Correct |
320 ms |
4420 KB |
Output is correct |
62 |
Correct |
325 ms |
4456 KB |
Output is correct |
63 |
Correct |
279 ms |
4456 KB |
Output is correct |
64 |
Correct |
270 ms |
4412 KB |
Output is correct |
65 |
Correct |
269 ms |
4580 KB |
Output is correct |
66 |
Correct |
137 ms |
4328 KB |
Output is correct |
67 |
Correct |
240 ms |
4460 KB |
Output is correct |
68 |
Correct |
236 ms |
4460 KB |
Output is correct |
69 |
Correct |
236 ms |
4456 KB |
Output is correct |
70 |
Correct |
236 ms |
4456 KB |
Output is correct |
71 |
Correct |
236 ms |
4440 KB |
Output is correct |
72 |
Correct |
237 ms |
4456 KB |
Output is correct |
73 |
Correct |
237 ms |
4516 KB |
Output is correct |
74 |
Correct |
236 ms |
4480 KB |
Output is correct |
75 |
Correct |
281 ms |
22400 KB |
Output is correct |
76 |
Correct |
274 ms |
22228 KB |
Output is correct |
77 |
Correct |
267 ms |
22424 KB |
Output is correct |
78 |
Correct |
274 ms |
22272 KB |
Output is correct |
79 |
Correct |
313 ms |
22048 KB |
Output is correct |
80 |
Correct |
275 ms |
22248 KB |
Output is correct |
81 |
Correct |
1085 ms |
21464 KB |
Output is correct |
82 |
Correct |
1106 ms |
21160 KB |
Output is correct |
83 |
Correct |
1080 ms |
21216 KB |
Output is correct |
84 |
Correct |
1104 ms |
21672 KB |
Output is correct |
85 |
Correct |
1075 ms |
21332 KB |
Output is correct |
86 |
Correct |
1076 ms |
21304 KB |
Output is correct |
87 |
Correct |
1120 ms |
21432 KB |
Output is correct |
88 |
Correct |
939 ms |
16608 KB |
Output is correct |
89 |
Correct |
924 ms |
16488 KB |
Output is correct |
90 |
Correct |
922 ms |
16624 KB |
Output is correct |
91 |
Correct |
900 ms |
16620 KB |
Output is correct |
92 |
Correct |
910 ms |
16576 KB |
Output is correct |
93 |
Correct |
933 ms |
20184 KB |
Output is correct |
94 |
Correct |
876 ms |
20952 KB |
Output is correct |
95 |
Correct |
936 ms |
20308 KB |
Output is correct |
96 |
Correct |
943 ms |
20184 KB |
Output is correct |
97 |
Correct |
1090 ms |
20108 KB |
Output is correct |
98 |
Correct |
606 ms |
20568 KB |
Output is correct |
99 |
Correct |
1016 ms |
20380 KB |
Output is correct |
100 |
Correct |
877 ms |
20308 KB |
Output is correct |
101 |
Correct |
762 ms |
20708 KB |
Output is correct |
102 |
Correct |
1008 ms |
20384 KB |
Output is correct |
103 |
Correct |
1022 ms |
20240 KB |
Output is correct |
104 |
Correct |
975 ms |
20180 KB |
Output is correct |
105 |
Correct |
469 ms |
18024 KB |
Output is correct |
106 |
Correct |
721 ms |
21084 KB |
Output is correct |
107 |
Correct |
725 ms |
21032 KB |
Output is correct |
108 |
Correct |
721 ms |
21212 KB |
Output is correct |
109 |
Correct |
725 ms |
21036 KB |
Output is correct |
110 |
Correct |
719 ms |
21076 KB |
Output is correct |
111 |
Correct |
724 ms |
21212 KB |
Output is correct |
112 |
Correct |
720 ms |
21144 KB |
Output is correct |
113 |
Correct |
726 ms |
21208 KB |
Output is correct |
114 |
Correct |
725 ms |
21080 KB |
Output is correct |
115 |
Correct |
726 ms |
20948 KB |
Output is correct |
116 |
Correct |
696 ms |
21028 KB |
Output is correct |