/*
https://codeforces.com/blog/entry/59650
*/
#include <bits/stdc++.h>
#define endl '\n'
#define SZ(x) ((int)x.size())
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
using namespace std;
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);
struct Circle
{
int idx, rad, x, y;
Circle() { idx = rad = x = y = 0; }
Circle(int _i, int _r, int _x, int _y)
{
idx = _i;
rad = _r;
x = _x;
y = _y;
}
};
inline int64_t sq(int x) { return x * 1ll * x; }
bool cmp(const Circle &a, const Circle &b) { return a.rad != b.rad ? a.rad > b.rad : a.idx < b.idx; }
bool intersect(const Circle &a, const Circle &b) { return sq(a.x - b.x) + sq(a.y - b.y) <= sq(a.rad + b.rad); }
int n;
int answer[MAXN];
Circle a[MAXN];
void read()
{
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i].x >> a[i].y >> a[i].rad;
a[i].idx = i;
}
}
map<pair<int, int>, vector<int> > M;
void rebuild(int block_size)
{
M.clear();
for(int i = 1; i <= n; i++)
if(!answer[a[i].idx])
M[{a[i].x / block_size, a[i].y / block_size}].push_back(i);
}
void solve()
{
sort(a + 1, a + n + 1, cmp);
int B = (1 << 30);
rebuild(B);
for(int i = 1; i <= n; i++)
{
if(answer[a[i].idx]) continue;
while(a[i].rad * 2 < (B >> 1))
{
B >>= 1;
rebuild(B);
}
answer[a[i].idx] = a[i].idx;
int x = a[i].x / B, y = a[i].y / B;
for(int dx = -1; dx <= 1; dx++)
for(int dy = -1; dy <= 1; dy++)
{
int nx = dx + x;
int ny = dy + y;
if(M.count({nx, ny}))
for(int j: M[{nx, ny}])
if(intersect(a[i], a[j]))
answer[a[j].idx] = a[i].idx;
}
}
for(int i = 1; i <= n; i++)
cout << answer[i] << " ";
cout << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
read();
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
16760 KB |
Output is correct |
2 |
Correct |
16 ms |
16940 KB |
Output is correct |
3 |
Correct |
16 ms |
16940 KB |
Output is correct |
4 |
Correct |
16 ms |
16940 KB |
Output is correct |
5 |
Correct |
19 ms |
16940 KB |
Output is correct |
6 |
Correct |
17 ms |
17088 KB |
Output is correct |
7 |
Correct |
16 ms |
17088 KB |
Output is correct |
8 |
Incorrect |
16 ms |
17088 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
193 ms |
22144 KB |
Output is correct |
2 |
Incorrect |
220 ms |
23124 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23124 KB |
Output is correct |
2 |
Correct |
779 ms |
30676 KB |
Output is correct |
3 |
Execution timed out |
3025 ms |
61152 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3050 ms |
61152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
16760 KB |
Output is correct |
2 |
Correct |
16 ms |
16940 KB |
Output is correct |
3 |
Correct |
16 ms |
16940 KB |
Output is correct |
4 |
Correct |
16 ms |
16940 KB |
Output is correct |
5 |
Correct |
19 ms |
16940 KB |
Output is correct |
6 |
Correct |
17 ms |
17088 KB |
Output is correct |
7 |
Correct |
16 ms |
17088 KB |
Output is correct |
8 |
Incorrect |
16 ms |
17088 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
16760 KB |
Output is correct |
2 |
Correct |
16 ms |
16940 KB |
Output is correct |
3 |
Correct |
16 ms |
16940 KB |
Output is correct |
4 |
Correct |
16 ms |
16940 KB |
Output is correct |
5 |
Correct |
19 ms |
16940 KB |
Output is correct |
6 |
Correct |
17 ms |
17088 KB |
Output is correct |
7 |
Correct |
16 ms |
17088 KB |
Output is correct |
8 |
Incorrect |
16 ms |
17088 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |