#include <bits/stdc++.h>
using namespace std;
void just_do_it();
int main() {
#ifdef KAMIRULEZ
freopen("kamirulez.inp", "r", stdin);
freopen("kamirulez.out", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
just_do_it();
return 0;
}
struct circle {
int x, y, r;
};
bool intersect(circle C1, circle C2) {
return 1LL * (C1.r + C2.r) * (C1.r + C2.r) >= 1LL * (C1.x - C2.x) * (C1.x - C2.x) + 1LL * (C1.y - C2.y) * (C1.y - C2.y);
}
const int maxn = 3e5 + 20;
circle C[maxn];
int res[maxn];
set<pair<int, int>> S;
map<int, vector<pair<int, int>>> groups;
int n;
int floor(int a, int b) {
return (a / b) - (a % b && (a ^ b) < 0);
}
void build(int len) {
groups.clear();
for (auto p: S) {
int i = p.second;
int cx = floor(C[i].x, len);
int cy = floor(C[i].y, len);
groups[cx].emplace_back(cy, i);
}
for (auto &p: groups) {
sort(p.second.begin(), p.second.end());
}
}
void just_do_it() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> C[i].x >> C[i].y >> C[i].r;
S.insert({-C[i].r, i});
}
int len = -1;
while (!S.empty()) {
int cur = S.begin()->second;
if (len == -1 || C[cur].r * 2 < len) {
len = C[cur].r;
build(len);
}
int cx = floor(C[cur].x, len);
int cy = floor(C[cur].y, len);
auto g_it = groups.lower_bound(cx - 2);
while (g_it != groups.end()) {
if (g_it->first > cx + 2) {
break;
}
auto it = lower_bound(g_it->second.begin(), g_it->second.end(), make_pair(cy - 2, -1));
while (it != g_it->second.end()) {
if (it->first > cy + 2) {
break;
}
int can = it->second;
if (!res[can] && intersect(C[cur], C[can])) {
res[can] = cur;
S.erase({-C[can].r, can});
}
it++;
}
g_it++;
}
}
for (int i = 1; i <= n; i++) {
cout << res[i] << " ";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
5 ms |
884 KB |
Output is correct |
20 |
Correct |
5 ms |
840 KB |
Output is correct |
21 |
Correct |
6 ms |
844 KB |
Output is correct |
22 |
Correct |
7 ms |
1108 KB |
Output is correct |
23 |
Correct |
9 ms |
900 KB |
Output is correct |
24 |
Correct |
10 ms |
1108 KB |
Output is correct |
25 |
Correct |
9 ms |
1308 KB |
Output is correct |
26 |
Correct |
8 ms |
1212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
493 ms |
22352 KB |
Output is correct |
2 |
Correct |
528 ms |
22372 KB |
Output is correct |
3 |
Correct |
509 ms |
24152 KB |
Output is correct |
4 |
Correct |
494 ms |
23616 KB |
Output is correct |
5 |
Correct |
552 ms |
26156 KB |
Output is correct |
6 |
Correct |
919 ms |
38668 KB |
Output is correct |
7 |
Correct |
637 ms |
27844 KB |
Output is correct |
8 |
Correct |
704 ms |
29936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
258 ms |
9664 KB |
Output is correct |
3 |
Correct |
1032 ms |
27920 KB |
Output is correct |
4 |
Correct |
1099 ms |
28072 KB |
Output is correct |
5 |
Correct |
977 ms |
24772 KB |
Output is correct |
6 |
Correct |
399 ms |
14084 KB |
Output is correct |
7 |
Correct |
141 ms |
8068 KB |
Output is correct |
8 |
Correct |
24 ms |
2680 KB |
Output is correct |
9 |
Correct |
1149 ms |
26568 KB |
Output is correct |
10 |
Correct |
944 ms |
24508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
711 ms |
33252 KB |
Output is correct |
2 |
Correct |
713 ms |
54812 KB |
Output is correct |
3 |
Correct |
469 ms |
25020 KB |
Output is correct |
4 |
Correct |
682 ms |
52312 KB |
Output is correct |
5 |
Correct |
705 ms |
53632 KB |
Output is correct |
6 |
Correct |
467 ms |
23964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
5 ms |
884 KB |
Output is correct |
20 |
Correct |
5 ms |
840 KB |
Output is correct |
21 |
Correct |
6 ms |
844 KB |
Output is correct |
22 |
Correct |
7 ms |
1108 KB |
Output is correct |
23 |
Correct |
9 ms |
900 KB |
Output is correct |
24 |
Correct |
10 ms |
1108 KB |
Output is correct |
25 |
Correct |
9 ms |
1308 KB |
Output is correct |
26 |
Correct |
8 ms |
1212 KB |
Output is correct |
27 |
Correct |
10 ms |
1316 KB |
Output is correct |
28 |
Correct |
10 ms |
1364 KB |
Output is correct |
29 |
Correct |
13 ms |
1364 KB |
Output is correct |
30 |
Correct |
19 ms |
1416 KB |
Output is correct |
31 |
Correct |
16 ms |
1820 KB |
Output is correct |
32 |
Correct |
16 ms |
1800 KB |
Output is correct |
33 |
Correct |
100 ms |
8416 KB |
Output is correct |
34 |
Correct |
104 ms |
8460 KB |
Output is correct |
35 |
Correct |
129 ms |
7956 KB |
Output is correct |
36 |
Correct |
247 ms |
12276 KB |
Output is correct |
37 |
Correct |
248 ms |
12084 KB |
Output is correct |
38 |
Correct |
302 ms |
10904 KB |
Output is correct |
39 |
Correct |
300 ms |
8772 KB |
Output is correct |
40 |
Correct |
317 ms |
8800 KB |
Output is correct |
41 |
Correct |
296 ms |
8944 KB |
Output is correct |
42 |
Correct |
118 ms |
8888 KB |
Output is correct |
43 |
Correct |
201 ms |
18020 KB |
Output is correct |
44 |
Correct |
177 ms |
18076 KB |
Output is correct |
45 |
Correct |
165 ms |
18068 KB |
Output is correct |
46 |
Correct |
234 ms |
18108 KB |
Output is correct |
47 |
Correct |
186 ms |
18000 KB |
Output is correct |
48 |
Correct |
183 ms |
18028 KB |
Output is correct |
49 |
Correct |
261 ms |
18012 KB |
Output is correct |
50 |
Correct |
195 ms |
18048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
5 ms |
884 KB |
Output is correct |
20 |
Correct |
5 ms |
840 KB |
Output is correct |
21 |
Correct |
6 ms |
844 KB |
Output is correct |
22 |
Correct |
7 ms |
1108 KB |
Output is correct |
23 |
Correct |
9 ms |
900 KB |
Output is correct |
24 |
Correct |
10 ms |
1108 KB |
Output is correct |
25 |
Correct |
9 ms |
1308 KB |
Output is correct |
26 |
Correct |
8 ms |
1212 KB |
Output is correct |
27 |
Correct |
493 ms |
22352 KB |
Output is correct |
28 |
Correct |
528 ms |
22372 KB |
Output is correct |
29 |
Correct |
509 ms |
24152 KB |
Output is correct |
30 |
Correct |
494 ms |
23616 KB |
Output is correct |
31 |
Correct |
552 ms |
26156 KB |
Output is correct |
32 |
Correct |
919 ms |
38668 KB |
Output is correct |
33 |
Correct |
637 ms |
27844 KB |
Output is correct |
34 |
Correct |
704 ms |
29936 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
258 ms |
9664 KB |
Output is correct |
37 |
Correct |
1032 ms |
27920 KB |
Output is correct |
38 |
Correct |
1099 ms |
28072 KB |
Output is correct |
39 |
Correct |
977 ms |
24772 KB |
Output is correct |
40 |
Correct |
399 ms |
14084 KB |
Output is correct |
41 |
Correct |
141 ms |
8068 KB |
Output is correct |
42 |
Correct |
24 ms |
2680 KB |
Output is correct |
43 |
Correct |
1149 ms |
26568 KB |
Output is correct |
44 |
Correct |
944 ms |
24508 KB |
Output is correct |
45 |
Correct |
711 ms |
33252 KB |
Output is correct |
46 |
Correct |
713 ms |
54812 KB |
Output is correct |
47 |
Correct |
469 ms |
25020 KB |
Output is correct |
48 |
Correct |
682 ms |
52312 KB |
Output is correct |
49 |
Correct |
705 ms |
53632 KB |
Output is correct |
50 |
Correct |
467 ms |
23964 KB |
Output is correct |
51 |
Correct |
10 ms |
1316 KB |
Output is correct |
52 |
Correct |
10 ms |
1364 KB |
Output is correct |
53 |
Correct |
13 ms |
1364 KB |
Output is correct |
54 |
Correct |
19 ms |
1416 KB |
Output is correct |
55 |
Correct |
16 ms |
1820 KB |
Output is correct |
56 |
Correct |
16 ms |
1800 KB |
Output is correct |
57 |
Correct |
100 ms |
8416 KB |
Output is correct |
58 |
Correct |
104 ms |
8460 KB |
Output is correct |
59 |
Correct |
129 ms |
7956 KB |
Output is correct |
60 |
Correct |
247 ms |
12276 KB |
Output is correct |
61 |
Correct |
248 ms |
12084 KB |
Output is correct |
62 |
Correct |
302 ms |
10904 KB |
Output is correct |
63 |
Correct |
300 ms |
8772 KB |
Output is correct |
64 |
Correct |
317 ms |
8800 KB |
Output is correct |
65 |
Correct |
296 ms |
8944 KB |
Output is correct |
66 |
Correct |
118 ms |
8888 KB |
Output is correct |
67 |
Correct |
201 ms |
18020 KB |
Output is correct |
68 |
Correct |
177 ms |
18076 KB |
Output is correct |
69 |
Correct |
165 ms |
18068 KB |
Output is correct |
70 |
Correct |
234 ms |
18108 KB |
Output is correct |
71 |
Correct |
186 ms |
18000 KB |
Output is correct |
72 |
Correct |
183 ms |
18028 KB |
Output is correct |
73 |
Correct |
261 ms |
18012 KB |
Output is correct |
74 |
Correct |
195 ms |
18048 KB |
Output is correct |
75 |
Correct |
522 ms |
22404 KB |
Output is correct |
76 |
Correct |
536 ms |
22188 KB |
Output is correct |
77 |
Correct |
540 ms |
24352 KB |
Output is correct |
78 |
Correct |
455 ms |
24024 KB |
Output is correct |
79 |
Correct |
580 ms |
22412 KB |
Output is correct |
80 |
Correct |
470 ms |
23984 KB |
Output is correct |
81 |
Correct |
1012 ms |
28592 KB |
Output is correct |
82 |
Correct |
1068 ms |
30324 KB |
Output is correct |
83 |
Correct |
1174 ms |
30220 KB |
Output is correct |
84 |
Correct |
1065 ms |
26812 KB |
Output is correct |
85 |
Correct |
1060 ms |
29248 KB |
Output is correct |
86 |
Correct |
1195 ms |
30844 KB |
Output is correct |
87 |
Correct |
851 ms |
24448 KB |
Output is correct |
88 |
Correct |
1111 ms |
25532 KB |
Output is correct |
89 |
Correct |
1060 ms |
28716 KB |
Output is correct |
90 |
Correct |
1169 ms |
28556 KB |
Output is correct |
91 |
Correct |
1045 ms |
28504 KB |
Output is correct |
92 |
Correct |
1145 ms |
28500 KB |
Output is correct |
93 |
Correct |
1102 ms |
57260 KB |
Output is correct |
94 |
Correct |
497 ms |
26860 KB |
Output is correct |
95 |
Correct |
1034 ms |
57460 KB |
Output is correct |
96 |
Correct |
1086 ms |
56344 KB |
Output is correct |
97 |
Correct |
609 ms |
26196 KB |
Output is correct |
98 |
Correct |
914 ms |
40500 KB |
Output is correct |
99 |
Correct |
1164 ms |
57368 KB |
Output is correct |
100 |
Correct |
852 ms |
57664 KB |
Output is correct |
101 |
Correct |
972 ms |
34736 KB |
Output is correct |
102 |
Correct |
1218 ms |
56468 KB |
Output is correct |
103 |
Correct |
608 ms |
25960 KB |
Output is correct |
104 |
Correct |
1094 ms |
57616 KB |
Output is correct |
105 |
Correct |
490 ms |
29760 KB |
Output is correct |
106 |
Correct |
745 ms |
50788 KB |
Output is correct |
107 |
Correct |
776 ms |
50592 KB |
Output is correct |
108 |
Correct |
757 ms |
50444 KB |
Output is correct |
109 |
Correct |
761 ms |
50452 KB |
Output is correct |
110 |
Correct |
773 ms |
50416 KB |
Output is correct |
111 |
Correct |
783 ms |
50216 KB |
Output is correct |
112 |
Correct |
768 ms |
50204 KB |
Output is correct |
113 |
Correct |
813 ms |
49764 KB |
Output is correct |
114 |
Correct |
806 ms |
49500 KB |
Output is correct |
115 |
Correct |
715 ms |
49232 KB |
Output is correct |
116 |
Correct |
774 ms |
53536 KB |
Output is correct |