#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) x.size()
const int N = 3e5 + 1;
const int inf = 1e9 + 7;
typedef vector<int> vi;
struct Circle {
int x, y;
int R, i;
int ans;
} C[N];
bool Share(Circle a,Circle b) {
long long dX = 1ll * (a.x - b.x) * (a.x - b.x);
long long dY = 1ll * (a.y - b.y) * (a.y - b.y);
long long dR = 1ll * (a.R + b.R) * (a.R + b.R);
return dX + dY <= dR;
}
ll encode(int x,int y) { return ((ll)x << 31) + y; }
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
for(int i = 0 ; i < n ; ++i) {
cin >> C[i].x; C[i].x += inf;
cin >> C[i].y; C[i].y += inf;
cin >> C[i].R;
C[i].i = i;
C[i].ans = -1;
}
sort(C,C + n,[&](Circle C1,Circle C2) {
if (C1.R != C2.R) return C1.R > C2.R;
if (C1.R == C2.R) return C1.i < C2.i;
});
int unit = 2e9 + 1;
unordered_map<ll,vi> Combi;
auto build = [&]() {
Combi.clear();
for(int i = 0 ; i < n ; ++i) if (C[i].ans < 0) {
int x = C[i].x / unit;
int y = C[i].y / unit;
Combi[encode(x,y)].pb(i);
}
};
for(int i = 0 ; i < n ; ++i) if (C[i].ans < 0) {
//cout << C[i].i << " ";
if (unit > C[i].R * 2) {
unit = C[i].R;
build();
}
int x = C[i].x / unit;
int y = C[i].y / unit;
for(int a = x - 2 ; a < x + 3 ; ++a)
for(int b = y - 2 ; b < y + 3 ; ++b) {
ll Hash = encode(a,b);
if(!Combi.count(Hash))
continue;
vi &v = Combi[Hash];
for(int j = 0 ; j < v.size() ; ++j) if (Share(C[i],C[v[j]])) {
C[v[j]].ans = C[i].i;
swap(v[j],v.back());
v.pop_back();
j--;
}
}
}
sort(C,C + n,[&](Circle C1,Circle C2) { return C1.i < C2.i; });
for(int i = 0 ; i < n ; ++i)
cout << C[i].ans + 1 << " ";
}
/*
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:80:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0 ; j < v.size() ; ++j) if (Share(C[i],C[v[j]])) {
~~^~~~~~~~~~
circle_selection.cpp: In lambda function:
circle_selection.cpp:47:5: warning: control reaches end of non-void function [-Wreturn-type]
});
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 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 |
376 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 |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
380 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 |
380 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
652 KB |
Output is correct |
20 |
Correct |
6 ms |
632 KB |
Output is correct |
21 |
Correct |
6 ms |
632 KB |
Output is correct |
22 |
Correct |
12 ms |
1016 KB |
Output is correct |
23 |
Correct |
13 ms |
988 KB |
Output is correct |
24 |
Correct |
12 ms |
1016 KB |
Output is correct |
25 |
Correct |
12 ms |
1048 KB |
Output is correct |
26 |
Correct |
13 ms |
1040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
228 ms |
15284 KB |
Output is correct |
2 |
Correct |
231 ms |
15372 KB |
Output is correct |
3 |
Correct |
241 ms |
16136 KB |
Output is correct |
4 |
Correct |
247 ms |
15528 KB |
Output is correct |
5 |
Correct |
424 ms |
13676 KB |
Output is correct |
6 |
Correct |
551 ms |
26148 KB |
Output is correct |
7 |
Correct |
258 ms |
15816 KB |
Output is correct |
8 |
Correct |
313 ms |
18356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
297 ms |
14356 KB |
Output is correct |
3 |
Correct |
1420 ms |
43288 KB |
Output is correct |
4 |
Correct |
1359 ms |
43296 KB |
Output is correct |
5 |
Correct |
1184 ms |
38772 KB |
Output is correct |
6 |
Correct |
434 ms |
19444 KB |
Output is correct |
7 |
Correct |
311 ms |
10504 KB |
Output is correct |
8 |
Correct |
29 ms |
2552 KB |
Output is correct |
9 |
Correct |
1353 ms |
42720 KB |
Output is correct |
10 |
Correct |
1082 ms |
38164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1419 ms |
43192 KB |
Output is correct |
2 |
Correct |
1378 ms |
42344 KB |
Output is correct |
3 |
Correct |
328 ms |
24588 KB |
Output is correct |
4 |
Correct |
1432 ms |
42816 KB |
Output is correct |
5 |
Correct |
1407 ms |
42864 KB |
Output is correct |
6 |
Correct |
244 ms |
19832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 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 |
376 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 |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
380 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 |
380 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
652 KB |
Output is correct |
20 |
Correct |
6 ms |
632 KB |
Output is correct |
21 |
Correct |
6 ms |
632 KB |
Output is correct |
22 |
Correct |
12 ms |
1016 KB |
Output is correct |
23 |
Correct |
13 ms |
988 KB |
Output is correct |
24 |
Correct |
12 ms |
1016 KB |
Output is correct |
25 |
Correct |
12 ms |
1048 KB |
Output is correct |
26 |
Correct |
13 ms |
1040 KB |
Output is correct |
27 |
Correct |
10 ms |
1016 KB |
Output is correct |
28 |
Correct |
10 ms |
1016 KB |
Output is correct |
29 |
Correct |
10 ms |
1016 KB |
Output is correct |
30 |
Correct |
24 ms |
1784 KB |
Output is correct |
31 |
Correct |
25 ms |
1784 KB |
Output is correct |
32 |
Correct |
24 ms |
1752 KB |
Output is correct |
33 |
Correct |
82 ms |
6760 KB |
Output is correct |
34 |
Correct |
82 ms |
6520 KB |
Output is correct |
35 |
Correct |
93 ms |
6052 KB |
Output is correct |
36 |
Correct |
311 ms |
14216 KB |
Output is correct |
37 |
Correct |
319 ms |
14216 KB |
Output is correct |
38 |
Correct |
315 ms |
14228 KB |
Output is correct |
39 |
Correct |
306 ms |
11652 KB |
Output is correct |
40 |
Correct |
319 ms |
11552 KB |
Output is correct |
41 |
Correct |
312 ms |
11608 KB |
Output is correct |
42 |
Correct |
138 ms |
13316 KB |
Output is correct |
43 |
Correct |
367 ms |
14056 KB |
Output is correct |
44 |
Correct |
308 ms |
14088 KB |
Output is correct |
45 |
Correct |
307 ms |
14092 KB |
Output is correct |
46 |
Correct |
293 ms |
14084 KB |
Output is correct |
47 |
Correct |
298 ms |
14048 KB |
Output is correct |
48 |
Correct |
306 ms |
14088 KB |
Output is correct |
49 |
Correct |
302 ms |
14088 KB |
Output is correct |
50 |
Correct |
275 ms |
14088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 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 |
376 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 |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
380 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 |
380 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
652 KB |
Output is correct |
20 |
Correct |
6 ms |
632 KB |
Output is correct |
21 |
Correct |
6 ms |
632 KB |
Output is correct |
22 |
Correct |
12 ms |
1016 KB |
Output is correct |
23 |
Correct |
13 ms |
988 KB |
Output is correct |
24 |
Correct |
12 ms |
1016 KB |
Output is correct |
25 |
Correct |
12 ms |
1048 KB |
Output is correct |
26 |
Correct |
13 ms |
1040 KB |
Output is correct |
27 |
Correct |
228 ms |
15284 KB |
Output is correct |
28 |
Correct |
231 ms |
15372 KB |
Output is correct |
29 |
Correct |
241 ms |
16136 KB |
Output is correct |
30 |
Correct |
247 ms |
15528 KB |
Output is correct |
31 |
Correct |
424 ms |
13676 KB |
Output is correct |
32 |
Correct |
551 ms |
26148 KB |
Output is correct |
33 |
Correct |
258 ms |
15816 KB |
Output is correct |
34 |
Correct |
313 ms |
18356 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
297 ms |
14356 KB |
Output is correct |
37 |
Correct |
1420 ms |
43288 KB |
Output is correct |
38 |
Correct |
1359 ms |
43296 KB |
Output is correct |
39 |
Correct |
1184 ms |
38772 KB |
Output is correct |
40 |
Correct |
434 ms |
19444 KB |
Output is correct |
41 |
Correct |
311 ms |
10504 KB |
Output is correct |
42 |
Correct |
29 ms |
2552 KB |
Output is correct |
43 |
Correct |
1353 ms |
42720 KB |
Output is correct |
44 |
Correct |
1082 ms |
38164 KB |
Output is correct |
45 |
Correct |
1419 ms |
43192 KB |
Output is correct |
46 |
Correct |
1378 ms |
42344 KB |
Output is correct |
47 |
Correct |
328 ms |
24588 KB |
Output is correct |
48 |
Correct |
1432 ms |
42816 KB |
Output is correct |
49 |
Correct |
1407 ms |
42864 KB |
Output is correct |
50 |
Correct |
244 ms |
19832 KB |
Output is correct |
51 |
Correct |
10 ms |
1016 KB |
Output is correct |
52 |
Correct |
10 ms |
1016 KB |
Output is correct |
53 |
Correct |
10 ms |
1016 KB |
Output is correct |
54 |
Correct |
24 ms |
1784 KB |
Output is correct |
55 |
Correct |
25 ms |
1784 KB |
Output is correct |
56 |
Correct |
24 ms |
1752 KB |
Output is correct |
57 |
Correct |
82 ms |
6760 KB |
Output is correct |
58 |
Correct |
82 ms |
6520 KB |
Output is correct |
59 |
Correct |
93 ms |
6052 KB |
Output is correct |
60 |
Correct |
311 ms |
14216 KB |
Output is correct |
61 |
Correct |
319 ms |
14216 KB |
Output is correct |
62 |
Correct |
315 ms |
14228 KB |
Output is correct |
63 |
Correct |
306 ms |
11652 KB |
Output is correct |
64 |
Correct |
319 ms |
11552 KB |
Output is correct |
65 |
Correct |
312 ms |
11608 KB |
Output is correct |
66 |
Correct |
138 ms |
13316 KB |
Output is correct |
67 |
Correct |
367 ms |
14056 KB |
Output is correct |
68 |
Correct |
308 ms |
14088 KB |
Output is correct |
69 |
Correct |
307 ms |
14092 KB |
Output is correct |
70 |
Correct |
293 ms |
14084 KB |
Output is correct |
71 |
Correct |
298 ms |
14048 KB |
Output is correct |
72 |
Correct |
306 ms |
14088 KB |
Output is correct |
73 |
Correct |
302 ms |
14088 KB |
Output is correct |
74 |
Correct |
275 ms |
14088 KB |
Output is correct |
75 |
Correct |
258 ms |
17620 KB |
Output is correct |
76 |
Correct |
253 ms |
17400 KB |
Output is correct |
77 |
Correct |
248 ms |
18508 KB |
Output is correct |
78 |
Correct |
244 ms |
18528 KB |
Output is correct |
79 |
Correct |
273 ms |
17120 KB |
Output is correct |
80 |
Correct |
245 ms |
18536 KB |
Output is correct |
81 |
Correct |
1317 ms |
43224 KB |
Output is correct |
82 |
Correct |
1396 ms |
43272 KB |
Output is correct |
83 |
Correct |
1362 ms |
43076 KB |
Output is correct |
84 |
Correct |
1384 ms |
43864 KB |
Output is correct |
85 |
Correct |
1456 ms |
43196 KB |
Output is correct |
86 |
Correct |
1417 ms |
43164 KB |
Output is correct |
87 |
Correct |
1428 ms |
43216 KB |
Output is correct |
88 |
Correct |
1220 ms |
35028 KB |
Output is correct |
89 |
Correct |
1277 ms |
35004 KB |
Output is correct |
90 |
Correct |
1115 ms |
35052 KB |
Output is correct |
91 |
Correct |
1188 ms |
35332 KB |
Output is correct |
92 |
Correct |
1163 ms |
35096 KB |
Output is correct |
93 |
Correct |
1387 ms |
42136 KB |
Output is correct |
94 |
Correct |
1215 ms |
42504 KB |
Output is correct |
95 |
Correct |
1429 ms |
42184 KB |
Output is correct |
96 |
Correct |
1179 ms |
42116 KB |
Output is correct |
97 |
Correct |
1283 ms |
42128 KB |
Output is correct |
98 |
Correct |
830 ms |
32312 KB |
Output is correct |
99 |
Correct |
1343 ms |
42244 KB |
Output is correct |
100 |
Correct |
1259 ms |
42116 KB |
Output is correct |
101 |
Correct |
845 ms |
37636 KB |
Output is correct |
102 |
Correct |
1193 ms |
41864 KB |
Output is correct |
103 |
Correct |
1229 ms |
41976 KB |
Output is correct |
104 |
Correct |
1324 ms |
41988 KB |
Output is correct |
105 |
Correct |
637 ms |
39824 KB |
Output is correct |
106 |
Correct |
1172 ms |
41500 KB |
Output is correct |
107 |
Correct |
1194 ms |
41436 KB |
Output is correct |
108 |
Correct |
1196 ms |
41404 KB |
Output is correct |
109 |
Correct |
1135 ms |
41516 KB |
Output is correct |
110 |
Correct |
1119 ms |
41452 KB |
Output is correct |
111 |
Correct |
1098 ms |
41468 KB |
Output is correct |
112 |
Correct |
1117 ms |
41476 KB |
Output is correct |
113 |
Correct |
1133 ms |
41552 KB |
Output is correct |
114 |
Correct |
1126 ms |
41476 KB |
Output is correct |
115 |
Correct |
1333 ms |
41608 KB |
Output is correct |
116 |
Correct |
1163 ms |
41496 KB |
Output is correct |