#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>
using namespace std;
struct cir
{
int x, y, r, i;
bool operator <(const cir &a) const
{
return r != a.r ? r > a.r : i < a.i;
}
};
const int MAXN = 300000;
const int MAXV = 1000000000;
cir arr[MAXN + 10];
int num[MAXN + 10];
int res[MAXN + 10];
int n;
bool inter(const cir &a, const cir &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);
}
vector<long long> com;
long long tmp[MAXN + 10];
vector<int> lis[MAXN + 10];
inline int idx(long long x)
{
return lower_bound(com.begin(), com.end(), x) - com.begin();
}
inline long long idx2(int x, int y, int r)
{
return (2LL * MAXV + 1) * ((x + MAXV) / r) + (y + MAXV) / r;
}
void init(int s, int mx)
{
com.clear();
for(int i = 0; i < n - s; i++)
lis[i].clear();
for(int i = s; i <= n; i++)
{
tmp[i] = idx2(arr[i].x, arr[i].y, mx);
com.push_back(tmp[i]);
}
sort(com.begin(), com.end());
com.erase(unique(com.begin(), com.end()), com.end());
for(int i = s; i <= n; i++)
lis[idx(tmp[i])].push_back(i);
}
int main()
{
//freopen("in", "r", stdin);
//freopen("out", "w", stdout);
int i, j, k;
scanf("%d", &n);
for(i = 1; i <= n; i++)
{
int x, y, r;
scanf("%d%d%d", &x, &y, &r);
arr[i] = { x, y, r, i };
}
sort(arr + 1, arr + n + 1);
int mx = arr[1].r;
init(1, mx);
for(i = 1; i <= n; i++)
{
if(num[i])
continue;
if(arr[i].r <= mx / 2)
{
mx = arr[i].r;
init(i, mx);
}
for(j = -2; j <= 2; j++)
{
for(k = -2; k <= 2; k++)
{
long long nx = arr[i].x + 1LL * j * mx;
long long ny = arr[i].y + 1LL * k * mx;
if(nx < -MAXV || nx > MAXV || ny < -MAXV || ny > MAXV)
continue;
long long t = idx2(nx, ny, mx);
int t2 = idx(t);
if(t2 == com.size() || com[t2] != t)
continue;
vector<int> nex;
for(int &x : lis[t2])
{
if(inter(arr[i], arr[x]))
num[x] = arr[i].i;
else
nex.push_back(x);
}
lis[t2] = nex;
}
}
}
for(i = 1; i <= n; i++)
res[arr[i].i] = num[i];
for(i = 1; i <= n; i++)
printf("%d ", res[i]);
return 0;
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:114:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(t2 == com.size() || com[t2] != t)
~~~^~~~~~~~~~~~~
circle_selection.cpp:80:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
circle_selection.cpp:84:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &x, &y, &r);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
7416 KB |
Output is correct |
2 |
Correct |
8 ms |
7528 KB |
Output is correct |
3 |
Correct |
8 ms |
7528 KB |
Output is correct |
4 |
Correct |
8 ms |
7568 KB |
Output is correct |
5 |
Correct |
8 ms |
7568 KB |
Output is correct |
6 |
Incorrect |
9 ms |
7696 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
237 ms |
23944 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
23944 KB |
Output is correct |
2 |
Correct |
388 ms |
23944 KB |
Output is correct |
3 |
Correct |
1247 ms |
30680 KB |
Output is correct |
4 |
Correct |
1202 ms |
30840 KB |
Output is correct |
5 |
Correct |
1308 ms |
30840 KB |
Output is correct |
6 |
Correct |
512 ms |
30840 KB |
Output is correct |
7 |
Correct |
240 ms |
30840 KB |
Output is correct |
8 |
Correct |
44 ms |
30840 KB |
Output is correct |
9 |
Correct |
1368 ms |
30840 KB |
Output is correct |
10 |
Correct |
1282 ms |
30840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1235 ms |
30840 KB |
Output is correct |
2 |
Correct |
973 ms |
30840 KB |
Output is correct |
3 |
Correct |
479 ms |
30840 KB |
Output is correct |
4 |
Correct |
1056 ms |
30840 KB |
Output is correct |
5 |
Correct |
1109 ms |
30840 KB |
Output is correct |
6 |
Correct |
305 ms |
30840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
7416 KB |
Output is correct |
2 |
Correct |
8 ms |
7528 KB |
Output is correct |
3 |
Correct |
8 ms |
7528 KB |
Output is correct |
4 |
Correct |
8 ms |
7568 KB |
Output is correct |
5 |
Correct |
8 ms |
7568 KB |
Output is correct |
6 |
Incorrect |
9 ms |
7696 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
7416 KB |
Output is correct |
2 |
Correct |
8 ms |
7528 KB |
Output is correct |
3 |
Correct |
8 ms |
7528 KB |
Output is correct |
4 |
Correct |
8 ms |
7568 KB |
Output is correct |
5 |
Correct |
8 ms |
7568 KB |
Output is correct |
6 |
Incorrect |
9 ms |
7696 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |