#include <bits/stdc++.h>
#define pii pair<int, int>
#define fi first
#define se second
#define task "main"
using namespace std;
const int N = (int)3e5 + 10;
struct Circle {
int x, y, r, i;
Circle(int _x = 0, int _y = 0, int _r = 0, int _i = 0) {
x = _x, y = _y, r = _r, i = _i;
}
} circles[N];
int n;
int res[N];
bool cmp(const Circle &a, const Circle &b){
if (a.r == b.r) return a.i < b.i;
return a.r > b.r;
}
bool intersect(const Circle &a, const 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);
}
void solve() {
cin >> n;
for(int i = 0; i < n; i++) {
cin >> circles[i].x >> circles[i].y >> circles[i].r;
circles[i].i = i;
}
sort (circles, circles + n, cmp);
memset(res, -1, sizeof res);
for (int lg = 30; lg >= 0; --lg) {
int r = (1 << lg);
map<pii, vector<int> > grid;
bool found = false;
for (int i = 0; i < n; ++i) {
if (res[circles[i].i] == -1 && circles[i].r >= r / 2 && circles[i].r <= r) {
found = true;
break;
}
}
if(!found) continue;
for (int i = 0; i < n; ++i) {
if (res[circles[i].i] == -1) {
grid[pii(circles[i].x / r, circles[i].y / r)].push_back(i);
}
}
for (int i = 0; i < n; ++i) {
if (circles[i].r < r / 2) break;
if (res[circles[i].i] != -1 || circles[i].r > r) continue;
for(int x = circles[i].x / r - 2; x <= circles[i].x / r + 2; ++x) {
for(int y = circles[i].y / r - 2; y <= circles[i].y / r + 2; ++y) {
if (grid.find(pii(x, y)) == grid.end()) continue;
vector<int> &candidates = grid[pii(x, y)];
for (int j = (int)candidates.size() - 1; j >= 0; --j) {
int c = candidates[j];
if (res[circles[c].i] == -1 && intersect(circles[c], circles[i])) {
res[circles[c].i] = circles[i].i;
swap (candidates[j], candidates.back());
candidates.pop_back();
}
}
}
}
}
}
for(int i = 0; i < n; i++) cout << res[i] + 1 << ' ';
}
int main() {
#ifdef LOCAL
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6232 KB |
Output is correct |
2 |
Correct |
3 ms |
6232 KB |
Output is correct |
3 |
Correct |
3 ms |
6236 KB |
Output is correct |
4 |
Correct |
2 ms |
6236 KB |
Output is correct |
5 |
Correct |
2 ms |
6184 KB |
Output is correct |
6 |
Correct |
3 ms |
6236 KB |
Output is correct |
7 |
Correct |
2 ms |
6300 KB |
Output is correct |
8 |
Correct |
2 ms |
6236 KB |
Output is correct |
9 |
Correct |
2 ms |
6240 KB |
Output is correct |
10 |
Correct |
2 ms |
6236 KB |
Output is correct |
11 |
Correct |
2 ms |
6236 KB |
Output is correct |
12 |
Correct |
2 ms |
6176 KB |
Output is correct |
13 |
Correct |
2 ms |
6296 KB |
Output is correct |
14 |
Correct |
3 ms |
6232 KB |
Output is correct |
15 |
Correct |
2 ms |
6236 KB |
Output is correct |
16 |
Correct |
3 ms |
6200 KB |
Output is correct |
17 |
Correct |
4 ms |
6488 KB |
Output is correct |
18 |
Correct |
5 ms |
6236 KB |
Output is correct |
19 |
Correct |
5 ms |
6492 KB |
Output is correct |
20 |
Correct |
4 ms |
6488 KB |
Output is correct |
21 |
Correct |
4 ms |
6492 KB |
Output is correct |
22 |
Correct |
11 ms |
6872 KB |
Output is correct |
23 |
Correct |
13 ms |
7028 KB |
Output is correct |
24 |
Correct |
11 ms |
7020 KB |
Output is correct |
25 |
Correct |
11 ms |
7004 KB |
Output is correct |
26 |
Correct |
12 ms |
7008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
15136 KB |
Output is correct |
2 |
Correct |
147 ms |
15948 KB |
Output is correct |
3 |
Correct |
118 ms |
15176 KB |
Output is correct |
4 |
Correct |
112 ms |
15132 KB |
Output is correct |
5 |
Correct |
174 ms |
15124 KB |
Output is correct |
6 |
Correct |
463 ms |
25488 KB |
Output is correct |
7 |
Correct |
228 ms |
16212 KB |
Output is correct |
8 |
Correct |
244 ms |
18576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
327 ms |
20512 KB |
Output is correct |
3 |
Correct |
1206 ms |
49232 KB |
Output is correct |
4 |
Correct |
1226 ms |
49232 KB |
Output is correct |
5 |
Correct |
1180 ms |
43660 KB |
Output is correct |
6 |
Correct |
399 ms |
24656 KB |
Output is correct |
7 |
Correct |
176 ms |
15952 KB |
Output is correct |
8 |
Correct |
25 ms |
8284 KB |
Output is correct |
9 |
Correct |
1392 ms |
47928 KB |
Output is correct |
10 |
Correct |
1018 ms |
40840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1020 ms |
48980 KB |
Output is correct |
2 |
Correct |
753 ms |
48216 KB |
Output is correct |
3 |
Correct |
258 ms |
24144 KB |
Output is correct |
4 |
Correct |
773 ms |
48400 KB |
Output is correct |
5 |
Correct |
726 ms |
48556 KB |
Output is correct |
6 |
Correct |
167 ms |
19200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6232 KB |
Output is correct |
2 |
Correct |
3 ms |
6232 KB |
Output is correct |
3 |
Correct |
3 ms |
6236 KB |
Output is correct |
4 |
Correct |
2 ms |
6236 KB |
Output is correct |
5 |
Correct |
2 ms |
6184 KB |
Output is correct |
6 |
Correct |
3 ms |
6236 KB |
Output is correct |
7 |
Correct |
2 ms |
6300 KB |
Output is correct |
8 |
Correct |
2 ms |
6236 KB |
Output is correct |
9 |
Correct |
2 ms |
6240 KB |
Output is correct |
10 |
Correct |
2 ms |
6236 KB |
Output is correct |
11 |
Correct |
2 ms |
6236 KB |
Output is correct |
12 |
Correct |
2 ms |
6176 KB |
Output is correct |
13 |
Correct |
2 ms |
6296 KB |
Output is correct |
14 |
Correct |
3 ms |
6232 KB |
Output is correct |
15 |
Correct |
2 ms |
6236 KB |
Output is correct |
16 |
Correct |
3 ms |
6200 KB |
Output is correct |
17 |
Correct |
4 ms |
6488 KB |
Output is correct |
18 |
Correct |
5 ms |
6236 KB |
Output is correct |
19 |
Correct |
5 ms |
6492 KB |
Output is correct |
20 |
Correct |
4 ms |
6488 KB |
Output is correct |
21 |
Correct |
4 ms |
6492 KB |
Output is correct |
22 |
Correct |
11 ms |
6872 KB |
Output is correct |
23 |
Correct |
13 ms |
7028 KB |
Output is correct |
24 |
Correct |
11 ms |
7020 KB |
Output is correct |
25 |
Correct |
11 ms |
7004 KB |
Output is correct |
26 |
Correct |
12 ms |
7008 KB |
Output is correct |
27 |
Correct |
6 ms |
6748 KB |
Output is correct |
28 |
Correct |
6 ms |
6748 KB |
Output is correct |
29 |
Correct |
6 ms |
6748 KB |
Output is correct |
30 |
Correct |
25 ms |
7476 KB |
Output is correct |
31 |
Correct |
24 ms |
7576 KB |
Output is correct |
32 |
Correct |
22 ms |
7512 KB |
Output is correct |
33 |
Correct |
42 ms |
10120 KB |
Output is correct |
34 |
Correct |
40 ms |
10012 KB |
Output is correct |
35 |
Correct |
46 ms |
9852 KB |
Output is correct |
36 |
Correct |
284 ms |
20304 KB |
Output is correct |
37 |
Correct |
271 ms |
20372 KB |
Output is correct |
38 |
Correct |
298 ms |
20420 KB |
Output is correct |
39 |
Correct |
240 ms |
13904 KB |
Output is correct |
40 |
Correct |
243 ms |
13912 KB |
Output is correct |
41 |
Correct |
248 ms |
13992 KB |
Output is correct |
42 |
Correct |
158 ms |
15120 KB |
Output is correct |
43 |
Correct |
225 ms |
19968 KB |
Output is correct |
44 |
Correct |
196 ms |
20052 KB |
Output is correct |
45 |
Correct |
193 ms |
20052 KB |
Output is correct |
46 |
Correct |
196 ms |
20048 KB |
Output is correct |
47 |
Correct |
187 ms |
20052 KB |
Output is correct |
48 |
Correct |
190 ms |
20108 KB |
Output is correct |
49 |
Correct |
185 ms |
20048 KB |
Output is correct |
50 |
Correct |
186 ms |
20048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6232 KB |
Output is correct |
2 |
Correct |
3 ms |
6232 KB |
Output is correct |
3 |
Correct |
3 ms |
6236 KB |
Output is correct |
4 |
Correct |
2 ms |
6236 KB |
Output is correct |
5 |
Correct |
2 ms |
6184 KB |
Output is correct |
6 |
Correct |
3 ms |
6236 KB |
Output is correct |
7 |
Correct |
2 ms |
6300 KB |
Output is correct |
8 |
Correct |
2 ms |
6236 KB |
Output is correct |
9 |
Correct |
2 ms |
6240 KB |
Output is correct |
10 |
Correct |
2 ms |
6236 KB |
Output is correct |
11 |
Correct |
2 ms |
6236 KB |
Output is correct |
12 |
Correct |
2 ms |
6176 KB |
Output is correct |
13 |
Correct |
2 ms |
6296 KB |
Output is correct |
14 |
Correct |
3 ms |
6232 KB |
Output is correct |
15 |
Correct |
2 ms |
6236 KB |
Output is correct |
16 |
Correct |
3 ms |
6200 KB |
Output is correct |
17 |
Correct |
4 ms |
6488 KB |
Output is correct |
18 |
Correct |
5 ms |
6236 KB |
Output is correct |
19 |
Correct |
5 ms |
6492 KB |
Output is correct |
20 |
Correct |
4 ms |
6488 KB |
Output is correct |
21 |
Correct |
4 ms |
6492 KB |
Output is correct |
22 |
Correct |
11 ms |
6872 KB |
Output is correct |
23 |
Correct |
13 ms |
7028 KB |
Output is correct |
24 |
Correct |
11 ms |
7020 KB |
Output is correct |
25 |
Correct |
11 ms |
7004 KB |
Output is correct |
26 |
Correct |
12 ms |
7008 KB |
Output is correct |
27 |
Correct |
116 ms |
15136 KB |
Output is correct |
28 |
Correct |
147 ms |
15948 KB |
Output is correct |
29 |
Correct |
118 ms |
15176 KB |
Output is correct |
30 |
Correct |
112 ms |
15132 KB |
Output is correct |
31 |
Correct |
174 ms |
15124 KB |
Output is correct |
32 |
Correct |
463 ms |
25488 KB |
Output is correct |
33 |
Correct |
228 ms |
16212 KB |
Output is correct |
34 |
Correct |
244 ms |
18576 KB |
Output is correct |
35 |
Correct |
2 ms |
6488 KB |
Output is correct |
36 |
Correct |
327 ms |
20512 KB |
Output is correct |
37 |
Correct |
1206 ms |
49232 KB |
Output is correct |
38 |
Correct |
1226 ms |
49232 KB |
Output is correct |
39 |
Correct |
1180 ms |
43660 KB |
Output is correct |
40 |
Correct |
399 ms |
24656 KB |
Output is correct |
41 |
Correct |
176 ms |
15952 KB |
Output is correct |
42 |
Correct |
25 ms |
8284 KB |
Output is correct |
43 |
Correct |
1392 ms |
47928 KB |
Output is correct |
44 |
Correct |
1018 ms |
40840 KB |
Output is correct |
45 |
Correct |
1020 ms |
48980 KB |
Output is correct |
46 |
Correct |
753 ms |
48216 KB |
Output is correct |
47 |
Correct |
258 ms |
24144 KB |
Output is correct |
48 |
Correct |
773 ms |
48400 KB |
Output is correct |
49 |
Correct |
726 ms |
48556 KB |
Output is correct |
50 |
Correct |
167 ms |
19200 KB |
Output is correct |
51 |
Correct |
6 ms |
6748 KB |
Output is correct |
52 |
Correct |
6 ms |
6748 KB |
Output is correct |
53 |
Correct |
6 ms |
6748 KB |
Output is correct |
54 |
Correct |
25 ms |
7476 KB |
Output is correct |
55 |
Correct |
24 ms |
7576 KB |
Output is correct |
56 |
Correct |
22 ms |
7512 KB |
Output is correct |
57 |
Correct |
42 ms |
10120 KB |
Output is correct |
58 |
Correct |
40 ms |
10012 KB |
Output is correct |
59 |
Correct |
46 ms |
9852 KB |
Output is correct |
60 |
Correct |
284 ms |
20304 KB |
Output is correct |
61 |
Correct |
271 ms |
20372 KB |
Output is correct |
62 |
Correct |
298 ms |
20420 KB |
Output is correct |
63 |
Correct |
240 ms |
13904 KB |
Output is correct |
64 |
Correct |
243 ms |
13912 KB |
Output is correct |
65 |
Correct |
248 ms |
13992 KB |
Output is correct |
66 |
Correct |
158 ms |
15120 KB |
Output is correct |
67 |
Correct |
225 ms |
19968 KB |
Output is correct |
68 |
Correct |
196 ms |
20052 KB |
Output is correct |
69 |
Correct |
193 ms |
20052 KB |
Output is correct |
70 |
Correct |
196 ms |
20048 KB |
Output is correct |
71 |
Correct |
187 ms |
20052 KB |
Output is correct |
72 |
Correct |
190 ms |
20108 KB |
Output is correct |
73 |
Correct |
185 ms |
20048 KB |
Output is correct |
74 |
Correct |
186 ms |
20048 KB |
Output is correct |
75 |
Correct |
141 ms |
17560 KB |
Output is correct |
76 |
Correct |
127 ms |
17476 KB |
Output is correct |
77 |
Correct |
122 ms |
17372 KB |
Output is correct |
78 |
Correct |
120 ms |
17356 KB |
Output is correct |
79 |
Correct |
156 ms |
17032 KB |
Output is correct |
80 |
Correct |
120 ms |
17292 KB |
Output is correct |
81 |
Correct |
1272 ms |
49020 KB |
Output is correct |
82 |
Correct |
1031 ms |
48840 KB |
Output is correct |
83 |
Correct |
1059 ms |
48976 KB |
Output is correct |
84 |
Correct |
1151 ms |
49236 KB |
Output is correct |
85 |
Correct |
1055 ms |
48980 KB |
Output is correct |
86 |
Correct |
1016 ms |
48980 KB |
Output is correct |
87 |
Correct |
1293 ms |
48672 KB |
Output is correct |
88 |
Correct |
879 ms |
29972 KB |
Output is correct |
89 |
Correct |
849 ms |
29912 KB |
Output is correct |
90 |
Correct |
855 ms |
30048 KB |
Output is correct |
91 |
Correct |
838 ms |
29996 KB |
Output is correct |
92 |
Correct |
845 ms |
29952 KB |
Output is correct |
93 |
Correct |
913 ms |
47848 KB |
Output is correct |
94 |
Correct |
915 ms |
48208 KB |
Output is correct |
95 |
Correct |
966 ms |
47956 KB |
Output is correct |
96 |
Correct |
1075 ms |
47728 KB |
Output is correct |
97 |
Correct |
1285 ms |
47956 KB |
Output is correct |
98 |
Correct |
542 ms |
31312 KB |
Output is correct |
99 |
Correct |
912 ms |
48208 KB |
Output is correct |
100 |
Correct |
878 ms |
47872 KB |
Output is correct |
101 |
Correct |
754 ms |
36760 KB |
Output is correct |
102 |
Correct |
877 ms |
47440 KB |
Output is correct |
103 |
Correct |
1388 ms |
46672 KB |
Output is correct |
104 |
Correct |
899 ms |
47876 KB |
Output is correct |
105 |
Correct |
578 ms |
32780 KB |
Output is correct |
106 |
Correct |
689 ms |
46488 KB |
Output is correct |
107 |
Correct |
665 ms |
46596 KB |
Output is correct |
108 |
Correct |
660 ms |
46520 KB |
Output is correct |
109 |
Correct |
670 ms |
46464 KB |
Output is correct |
110 |
Correct |
672 ms |
46476 KB |
Output is correct |
111 |
Correct |
692 ms |
46508 KB |
Output is correct |
112 |
Correct |
674 ms |
46464 KB |
Output is correct |
113 |
Correct |
667 ms |
46528 KB |
Output is correct |
114 |
Correct |
697 ms |
46536 KB |
Output is correct |
115 |
Correct |
673 ms |
46520 KB |
Output is correct |
116 |
Correct |
673 ms |
46416 KB |
Output is correct |