/*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 <ext/pb_ds/assoc_container.hpp>
// #include <unordered_map>
using namespace std;
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;
__gnu_pbds::gp_hash_table<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;
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 += 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 << ' ';
}
# |
Verdict |
Execution time |
Memory |
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 |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
4 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 |
384 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 |
512 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 |
768 KB |
Output is correct |
20 |
Correct |
8 ms |
768 KB |
Output is correct |
21 |
Correct |
8 ms |
768 KB |
Output is correct |
22 |
Correct |
12 ms |
1884 KB |
Output is correct |
23 |
Correct |
13 ms |
2068 KB |
Output is correct |
24 |
Correct |
14 ms |
1884 KB |
Output is correct |
25 |
Correct |
12 ms |
1884 KB |
Output is correct |
26 |
Correct |
13 ms |
2068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
195 ms |
15016 KB |
Output is correct |
2 |
Correct |
197 ms |
14504 KB |
Output is correct |
3 |
Correct |
197 ms |
14408 KB |
Output is correct |
4 |
Correct |
186 ms |
14384 KB |
Output is correct |
5 |
Correct |
1906 ms |
14964 KB |
Output is correct |
6 |
Execution timed out |
3078 ms |
21920 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Execution timed out |
3070 ms |
15024 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3074 ms |
31492 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
4 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 |
384 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 |
512 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 |
768 KB |
Output is correct |
20 |
Correct |
8 ms |
768 KB |
Output is correct |
21 |
Correct |
8 ms |
768 KB |
Output is correct |
22 |
Correct |
12 ms |
1884 KB |
Output is correct |
23 |
Correct |
13 ms |
2068 KB |
Output is correct |
24 |
Correct |
14 ms |
1884 KB |
Output is correct |
25 |
Correct |
12 ms |
1884 KB |
Output is correct |
26 |
Correct |
13 ms |
2068 KB |
Output is correct |
27 |
Correct |
11 ms |
1152 KB |
Output is correct |
28 |
Correct |
11 ms |
1152 KB |
Output is correct |
29 |
Correct |
11 ms |
1152 KB |
Output is correct |
30 |
Correct |
19 ms |
3492 KB |
Output is correct |
31 |
Correct |
892 ms |
3972 KB |
Output is correct |
32 |
Correct |
19 ms |
3480 KB |
Output is correct |
33 |
Correct |
72 ms |
5740 KB |
Output is correct |
34 |
Correct |
73 ms |
5740 KB |
Output is correct |
35 |
Correct |
68 ms |
5956 KB |
Output is correct |
36 |
Execution timed out |
3069 ms |
14728 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
4 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 |
384 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 |
512 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 |
768 KB |
Output is correct |
20 |
Correct |
8 ms |
768 KB |
Output is correct |
21 |
Correct |
8 ms |
768 KB |
Output is correct |
22 |
Correct |
12 ms |
1884 KB |
Output is correct |
23 |
Correct |
13 ms |
2068 KB |
Output is correct |
24 |
Correct |
14 ms |
1884 KB |
Output is correct |
25 |
Correct |
12 ms |
1884 KB |
Output is correct |
26 |
Correct |
13 ms |
2068 KB |
Output is correct |
27 |
Correct |
195 ms |
15016 KB |
Output is correct |
28 |
Correct |
197 ms |
14504 KB |
Output is correct |
29 |
Correct |
197 ms |
14408 KB |
Output is correct |
30 |
Correct |
186 ms |
14384 KB |
Output is correct |
31 |
Correct |
1906 ms |
14964 KB |
Output is correct |
32 |
Execution timed out |
3078 ms |
21920 KB |
Time limit exceeded |
33 |
Halted |
0 ms |
0 KB |
- |