/*input
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
*/
// spoiled
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <random>
#include <chrono>
#include <unordered_map>
using namespace std;
mt19937 rng(/*chrono::system_clock().now().time_since_epoch().count()*/100);
inline long long sqr(int x) { return (long long) x * x; }
struct Circle
{
int x, y, r, i;
bool intersect(const Circle &c) const
{
return sqr(c.x - x) + sqr(c.y - y) <= sqr(r + c.r);
}
};
const int OFFSET = 1000 * 1000 * 1000;
int N;
vector<Circle> cir;
vector<int> ans;
unordered_map<long long, vector<int>> grid;
inline long long hsh(int x, int y) { return (((long long) x) << 30 ^ y); }
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N;
// N = 300000;
ans.assign(N, -1);
cir.resize(N);
for (int i = 0; i < N; ++i) {
cin >> cir[i].x >> cir[i].y >> cir[i].r;
// cir[i].x = rng() % OFFSET, cir[i].y = rng() % OFFSET, cir[i].r = exp(1.0 * rng() / mt19937::max() * log(10000));
cir[i].x += OFFSET;
cir[i].y += OFFSET;
cir[i].i = i;
}
auto vec = cir;
sort(vec.begin(), vec.end(), [&](Circle &a, Circle &b) {
return (a.r == b.r ? (a.i < b.i) : (a.r > b.r));
});
auto c = vec.begin();
for (int i = 30; i >= 0; --i) {
if (c != vec.end() && c->r > ((1 << i) >> 1)) {
grid.clear();
for (auto t : vec) if (!~ans[t.i]) {
grid[hsh(t.x >> i, t.y >> i)].push_back(t.i);
}
}
for (; c != vec.end() && c->r > ((1 << i) >> 1); ++c) if (!~ans[c->i]) {
int cx = c->x >> i, cy = c->y >> i;
for (int tx = cx - 2; tx <= cx + 2; ++tx) {
for (int ty = cy - 2; ty <= cy + 2; ++ty) {
if (grid.find(hsh(tx, ty)) == grid.end()) continue;
vector<int> &cur = grid[hsh(tx, ty)], tmp;
for (int id : cur) {
if (c->intersect(cir[id])) {
ans[id] = c->i;
} else {
tmp.push_back(id);
}
}
cur = move(tmp);
}
}
}
}
for (int i = 0; i < N; ++i) cout << ans[i] + 1 << ' ';
cerr << 1.0 * clock() / CLOCKS_PER_SEC << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
8 ms |
640 KB |
Output is correct |
20 |
Correct |
8 ms |
640 KB |
Output is correct |
21 |
Correct |
8 ms |
640 KB |
Output is correct |
22 |
Correct |
13 ms |
1024 KB |
Output is correct |
23 |
Correct |
15 ms |
1024 KB |
Output is correct |
24 |
Correct |
12 ms |
1024 KB |
Output is correct |
25 |
Correct |
13 ms |
1024 KB |
Output is correct |
26 |
Correct |
13 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
207 ms |
13992 KB |
Output is correct |
2 |
Correct |
200 ms |
13208 KB |
Output is correct |
3 |
Correct |
200 ms |
13516 KB |
Output is correct |
4 |
Correct |
207 ms |
13260 KB |
Output is correct |
5 |
Correct |
207 ms |
13236 KB |
Output is correct |
6 |
Correct |
478 ms |
24016 KB |
Output is correct |
7 |
Correct |
225 ms |
15992 KB |
Output is correct |
8 |
Correct |
252 ms |
17860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
274 ms |
13192 KB |
Output is correct |
3 |
Correct |
974 ms |
39840 KB |
Output is correct |
4 |
Correct |
1059 ms |
40076 KB |
Output is correct |
5 |
Correct |
1006 ms |
35852 KB |
Output is correct |
6 |
Correct |
363 ms |
18108 KB |
Output is correct |
7 |
Correct |
140 ms |
9736 KB |
Output is correct |
8 |
Correct |
26 ms |
2552 KB |
Output is correct |
9 |
Correct |
1108 ms |
39180 KB |
Output is correct |
10 |
Correct |
899 ms |
33804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
890 ms |
39860 KB |
Output is correct |
2 |
Correct |
901 ms |
40116 KB |
Output is correct |
3 |
Correct |
332 ms |
27912 KB |
Output is correct |
4 |
Correct |
918 ms |
47500 KB |
Output is correct |
5 |
Correct |
884 ms |
47496 KB |
Output is correct |
6 |
Correct |
222 ms |
23800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
8 ms |
640 KB |
Output is correct |
20 |
Correct |
8 ms |
640 KB |
Output is correct |
21 |
Correct |
8 ms |
640 KB |
Output is correct |
22 |
Correct |
13 ms |
1024 KB |
Output is correct |
23 |
Correct |
15 ms |
1024 KB |
Output is correct |
24 |
Correct |
12 ms |
1024 KB |
Output is correct |
25 |
Correct |
13 ms |
1024 KB |
Output is correct |
26 |
Correct |
13 ms |
1024 KB |
Output is correct |
27 |
Correct |
11 ms |
896 KB |
Output is correct |
28 |
Correct |
13 ms |
896 KB |
Output is correct |
29 |
Correct |
11 ms |
768 KB |
Output is correct |
30 |
Correct |
22 ms |
1712 KB |
Output is correct |
31 |
Correct |
22 ms |
1664 KB |
Output is correct |
32 |
Correct |
21 ms |
1664 KB |
Output is correct |
33 |
Correct |
74 ms |
4588 KB |
Output is correct |
34 |
Correct |
73 ms |
4716 KB |
Output is correct |
35 |
Correct |
75 ms |
4704 KB |
Output is correct |
36 |
Correct |
286 ms |
13196 KB |
Output is correct |
37 |
Correct |
267 ms |
13192 KB |
Output is correct |
38 |
Correct |
262 ms |
13192 KB |
Output is correct |
39 |
Correct |
253 ms |
12052 KB |
Output is correct |
40 |
Correct |
263 ms |
12132 KB |
Output is correct |
41 |
Correct |
251 ms |
12036 KB |
Output is correct |
42 |
Correct |
136 ms |
10096 KB |
Output is correct |
43 |
Correct |
264 ms |
12936 KB |
Output is correct |
44 |
Correct |
227 ms |
12936 KB |
Output is correct |
45 |
Correct |
230 ms |
12936 KB |
Output is correct |
46 |
Correct |
243 ms |
12936 KB |
Output is correct |
47 |
Correct |
228 ms |
13064 KB |
Output is correct |
48 |
Correct |
292 ms |
13064 KB |
Output is correct |
49 |
Correct |
230 ms |
12936 KB |
Output is correct |
50 |
Correct |
257 ms |
12968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
8 ms |
640 KB |
Output is correct |
20 |
Correct |
8 ms |
640 KB |
Output is correct |
21 |
Correct |
8 ms |
640 KB |
Output is correct |
22 |
Correct |
13 ms |
1024 KB |
Output is correct |
23 |
Correct |
15 ms |
1024 KB |
Output is correct |
24 |
Correct |
12 ms |
1024 KB |
Output is correct |
25 |
Correct |
13 ms |
1024 KB |
Output is correct |
26 |
Correct |
13 ms |
1024 KB |
Output is correct |
27 |
Correct |
207 ms |
13992 KB |
Output is correct |
28 |
Correct |
200 ms |
13208 KB |
Output is correct |
29 |
Correct |
200 ms |
13516 KB |
Output is correct |
30 |
Correct |
207 ms |
13260 KB |
Output is correct |
31 |
Correct |
207 ms |
13236 KB |
Output is correct |
32 |
Correct |
478 ms |
24016 KB |
Output is correct |
33 |
Correct |
225 ms |
15992 KB |
Output is correct |
34 |
Correct |
252 ms |
17860 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
274 ms |
13192 KB |
Output is correct |
37 |
Correct |
974 ms |
39840 KB |
Output is correct |
38 |
Correct |
1059 ms |
40076 KB |
Output is correct |
39 |
Correct |
1006 ms |
35852 KB |
Output is correct |
40 |
Correct |
363 ms |
18108 KB |
Output is correct |
41 |
Correct |
140 ms |
9736 KB |
Output is correct |
42 |
Correct |
26 ms |
2552 KB |
Output is correct |
43 |
Correct |
1108 ms |
39180 KB |
Output is correct |
44 |
Correct |
899 ms |
33804 KB |
Output is correct |
45 |
Correct |
890 ms |
39860 KB |
Output is correct |
46 |
Correct |
901 ms |
40116 KB |
Output is correct |
47 |
Correct |
332 ms |
27912 KB |
Output is correct |
48 |
Correct |
918 ms |
47500 KB |
Output is correct |
49 |
Correct |
884 ms |
47496 KB |
Output is correct |
50 |
Correct |
222 ms |
23800 KB |
Output is correct |
51 |
Correct |
11 ms |
896 KB |
Output is correct |
52 |
Correct |
13 ms |
896 KB |
Output is correct |
53 |
Correct |
11 ms |
768 KB |
Output is correct |
54 |
Correct |
22 ms |
1712 KB |
Output is correct |
55 |
Correct |
22 ms |
1664 KB |
Output is correct |
56 |
Correct |
21 ms |
1664 KB |
Output is correct |
57 |
Correct |
74 ms |
4588 KB |
Output is correct |
58 |
Correct |
73 ms |
4716 KB |
Output is correct |
59 |
Correct |
75 ms |
4704 KB |
Output is correct |
60 |
Correct |
286 ms |
13196 KB |
Output is correct |
61 |
Correct |
267 ms |
13192 KB |
Output is correct |
62 |
Correct |
262 ms |
13192 KB |
Output is correct |
63 |
Correct |
253 ms |
12052 KB |
Output is correct |
64 |
Correct |
263 ms |
12132 KB |
Output is correct |
65 |
Correct |
251 ms |
12036 KB |
Output is correct |
66 |
Correct |
136 ms |
10096 KB |
Output is correct |
67 |
Correct |
264 ms |
12936 KB |
Output is correct |
68 |
Correct |
227 ms |
12936 KB |
Output is correct |
69 |
Correct |
230 ms |
12936 KB |
Output is correct |
70 |
Correct |
243 ms |
12936 KB |
Output is correct |
71 |
Correct |
228 ms |
13064 KB |
Output is correct |
72 |
Correct |
292 ms |
13064 KB |
Output is correct |
73 |
Correct |
230 ms |
12936 KB |
Output is correct |
74 |
Correct |
257 ms |
12968 KB |
Output is correct |
75 |
Correct |
236 ms |
22740 KB |
Output is correct |
76 |
Correct |
214 ms |
22372 KB |
Output is correct |
77 |
Correct |
232 ms |
22584 KB |
Output is correct |
78 |
Correct |
218 ms |
22160 KB |
Output is correct |
79 |
Correct |
244 ms |
21740 KB |
Output is correct |
80 |
Correct |
213 ms |
22144 KB |
Output is correct |
81 |
Correct |
1120 ms |
48008 KB |
Output is correct |
82 |
Correct |
963 ms |
47884 KB |
Output is correct |
83 |
Correct |
1004 ms |
47752 KB |
Output is correct |
84 |
Correct |
1050 ms |
48156 KB |
Output is correct |
85 |
Correct |
1010 ms |
47880 KB |
Output is correct |
86 |
Correct |
971 ms |
47880 KB |
Output is correct |
87 |
Correct |
987 ms |
47752 KB |
Output is correct |
88 |
Correct |
906 ms |
39820 KB |
Output is correct |
89 |
Correct |
920 ms |
39832 KB |
Output is correct |
90 |
Correct |
915 ms |
39764 KB |
Output is correct |
91 |
Correct |
910 ms |
39816 KB |
Output is correct |
92 |
Correct |
968 ms |
39744 KB |
Output is correct |
93 |
Correct |
1113 ms |
46988 KB |
Output is correct |
94 |
Correct |
987 ms |
46984 KB |
Output is correct |
95 |
Correct |
1058 ms |
46784 KB |
Output is correct |
96 |
Correct |
988 ms |
46860 KB |
Output is correct |
97 |
Correct |
1006 ms |
46728 KB |
Output is correct |
98 |
Correct |
685 ms |
33468 KB |
Output is correct |
99 |
Correct |
1063 ms |
47208 KB |
Output is correct |
100 |
Correct |
983 ms |
46760 KB |
Output is correct |
101 |
Correct |
1022 ms |
37180 KB |
Output is correct |
102 |
Correct |
1014 ms |
46476 KB |
Output is correct |
103 |
Correct |
1091 ms |
45836 KB |
Output is correct |
104 |
Correct |
1113 ms |
46692 KB |
Output is correct |
105 |
Correct |
654 ms |
33760 KB |
Output is correct |
106 |
Correct |
727 ms |
45960 KB |
Output is correct |
107 |
Correct |
747 ms |
46216 KB |
Output is correct |
108 |
Correct |
893 ms |
46088 KB |
Output is correct |
109 |
Correct |
864 ms |
46088 KB |
Output is correct |
110 |
Correct |
797 ms |
46220 KB |
Output is correct |
111 |
Correct |
768 ms |
46100 KB |
Output is correct |
112 |
Correct |
767 ms |
46044 KB |
Output is correct |
113 |
Correct |
822 ms |
46180 KB |
Output is correct |
114 |
Correct |
875 ms |
46168 KB |
Output is correct |
115 |
Correct |
995 ms |
46224 KB |
Output is correct |
116 |
Correct |
847 ms |
46088 KB |
Output is correct |