#include <bits/stdc++.h>
#define all(dataStructure) dataStructure.begin(),dataStructure.end()
typedef long long ll;
using namespace std;
namespace std {
template <typename T, int D>
struct _vector : public vector <_vector <T, D - 1>> {
static_assert(D >= 1, "Dimension must be positive!");
template <typename... Args>
_vector(int n = 0, Args... args) : vector <_vector <T, D - 1>> (n, _vector <T, D - 1> (args...)) {}
};
// _vector <int, 3> a(n, m, k);: int a[n][m][k].
// _vector <int, 3> a(n, m, k, x);: int a[n][m][k] initialized with x.
template <typename T>
struct _vector <T, 1> : public vector <T> {
_vector(int n = 0, const T& val = T()) : vector <T> (n, val) {}
};
}
const int MAX = 3e5 + 3;
const ll MOD[] = {1000000007, 998244353};
int n;
int ans[MAX];
ll x[MAX], y[MAX], r[MAX];
ll dist(int i, int j) {
return (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
}
void bruteForce() {
while (1) {
int chosen = 0;
for (int i = 1; i <= n; i++) if (!ans[i]) {
if (r[i] > r[chosen]) chosen = i;
}
if (!chosen) break;
for (int i = 1; i <= n; i++) if (!ans[i]) {
if ((r[i] + r[chosen]) * (r[i] + r[chosen]) >= dist(i, chosen)) ans[i] = chosen;
}
}
for (int i = 1; i <= n; i++) cout << ans[i] << ' ';
}
template <typename dataType>
inline void compress(vector <dataType> &x) {
sort(all(x));
x.erase(unique(all(x)), x.end());
}
namespace sameHeight {
vector <int> f[2][MAX];
int st[2][MAX << 2];
bool cmp0(int i, int j) {
return r[i] - x[i] < r[j] - x[j];
}
bool cmp1(int i, int j) {
return r[i] + x[i] < r[j] + x[j];
}
int choose(int type, int i, int j) {
if (i == 0) return j;
if (j == 0) return i;
if (type == 0) return r[i] - x[i] > r[j] - x[j] ? i : j;
return r[i] + x[i] > r[j] + x[j] ? i : j;
}
void build(int id, int l, int r) {
if (l == r) {
for (int type = 0; type <= 1; type++) {
st[type][id] = f[type][l].empty() ? 0 : f[type][l].back();
}
} else {
int mid = (l + r) / 2;
build(id << 1, l, mid);
build(id << 1 | 1, mid + 1, r);
for (int type = 0; type <= 1; type++) st[type][id] = choose(type, st[type][id << 1], st[type][id << 1 | 1]);
}
}
int get(int type, int u, int v, int id = 1, int l = 1, int r = n) {
if (u > v || v < l || r < u) return 0;
if (u <= l && r <= v) return st[type][id];
int mid = (l + r) / 2;
return choose(type, get(type, u, v, id << 1, l, mid), get(type, u, v, id << 1 | 1, mid + 1, r));
}
void del(int type, int pos, int id = 1, int l = 1, int r = n) {
if (l == r) {
f[type][l].pop_back();
st[type][id] = f[type][l].empty() ? 0 : f[type][l].back();
} else {
int mid = (l + r) / 2;
if (pos <= mid) del(type, pos, id << 1, l, mid);
else del(type, pos, id << 1 | 1, mid + 1, r);
st[type][id] = choose(type, st[type][id << 1], st[type][id << 1 | 1]);
}
}
void process() {
vector <ll> valX;
for (int i = 1; i <= n; i++) valX.push_back(x[i]);
compress(valX);
for (int i = 1; i <= n; i++) {
int id = lower_bound(all(valX), x[i]) - valX.begin() + 1;
f[0][id].push_back(i);
f[1][id].push_back(i);
}
for (int x = 1; x <= n; x++) {
sort(all(f[0][x]), cmp0);
sort(all(f[1][x]), cmp1);
}
build(1, 1, n);
vector <int> idx(n);
iota(all(idx), 1);
sort(all(idx), [&](const int &i, const int &j) {
if (r[i] != r[j]) return r[i] > r[j];
return i < j;
});
for (int &i : idx) {
if (ans[i]) continue;
int id = lower_bound(all(valX), x[i]) - valX.begin() + 1;
while (1) {
int chosen = get(1, 1, id);
if (x[i] - x[chosen] > r[i] + r[chosen]) break;
if (!ans[chosen]) ans[chosen] = i;
if (chosen) {
int pos = lower_bound(all(valX), x[chosen]) - valX.begin() + 1;
del(1, pos);
}
else break;
}
while (1) {
int chosen = get(0, id, n);
if (x[chosen] - x[i] > r[i] + r[chosen]) break;
if (!ans[chosen]) ans[chosen] = i;
if (chosen) {
int pos = lower_bound(all(valX), x[chosen]) - valX.begin() + 1;
del(0, pos);
}
else break;
}
}
for (int i = 1; i <= n; i++) cout << ans[i] << ' ';
}
}
void Solve() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> r[i];
if (n <= 5000) return bruteForce();
if (*max_element(y + 1, y + n + 1) == *min_element(y + 1, y + n + 1)) return sameHeight::process();
}
int32_t main() {
std::ios_base::sync_with_stdio(0);
std::cin.tie(0); std::cout.tie(0);
#define TASK "CC"
if (fopen(TASK".INP", "r")) {
freopen(TASK".INP", "r", stdin);
freopen(TASK".OUT", "w", stdout);
}
if (fopen("TASK.INP", "r")) {
freopen("TASK.INP", "r", stdin);
freopen("TASK.OUT", "w", stdout);
}
/* int TEST = 1; cin >> TEST; while (TEST--) */ Solve();
cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
return 0;
}
Compilation message
circle_selection.cpp: In function 'int32_t main()':
circle_selection.cpp:173:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
173 | freopen(TASK".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:174:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
174 | freopen(TASK".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:178:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
178 | freopen("TASK.INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:179:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
179 | freopen("TASK.OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
20816 KB |
Output is correct |
2 |
Correct |
4 ms |
20816 KB |
Output is correct |
3 |
Correct |
5 ms |
20816 KB |
Output is correct |
4 |
Correct |
4 ms |
20816 KB |
Output is correct |
5 |
Correct |
4 ms |
20816 KB |
Output is correct |
6 |
Correct |
4 ms |
20816 KB |
Output is correct |
7 |
Correct |
4 ms |
20816 KB |
Output is correct |
8 |
Correct |
3 ms |
20816 KB |
Output is correct |
9 |
Correct |
4 ms |
20944 KB |
Output is correct |
10 |
Correct |
4 ms |
20816 KB |
Output is correct |
11 |
Correct |
4 ms |
20816 KB |
Output is correct |
12 |
Correct |
4 ms |
20816 KB |
Output is correct |
13 |
Correct |
4 ms |
20816 KB |
Output is correct |
14 |
Correct |
5 ms |
20824 KB |
Output is correct |
15 |
Correct |
4 ms |
20860 KB |
Output is correct |
16 |
Correct |
4 ms |
20984 KB |
Output is correct |
17 |
Correct |
4 ms |
20816 KB |
Output is correct |
18 |
Correct |
4 ms |
20816 KB |
Output is correct |
19 |
Correct |
5 ms |
21072 KB |
Output is correct |
20 |
Correct |
5 ms |
20816 KB |
Output is correct |
21 |
Correct |
5 ms |
20816 KB |
Output is correct |
22 |
Correct |
74 ms |
21300 KB |
Output is correct |
23 |
Correct |
75 ms |
21072 KB |
Output is correct |
24 |
Correct |
77 ms |
20948 KB |
Output is correct |
25 |
Correct |
82 ms |
21064 KB |
Output is correct |
26 |
Correct |
74 ms |
20816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
481 ms |
60268 KB |
Output is correct |
2 |
Correct |
509 ms |
58296 KB |
Output is correct |
3 |
Correct |
479 ms |
57960 KB |
Output is correct |
4 |
Correct |
508 ms |
58296 KB |
Output is correct |
5 |
Correct |
415 ms |
51892 KB |
Output is correct |
6 |
Correct |
530 ms |
60596 KB |
Output is correct |
7 |
Correct |
459 ms |
59576 KB |
Output is correct |
8 |
Correct |
467 ms |
57532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
20816 KB |
Output is correct |
2 |
Incorrect |
27 ms |
24552 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
79 ms |
23028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
20816 KB |
Output is correct |
2 |
Correct |
4 ms |
20816 KB |
Output is correct |
3 |
Correct |
5 ms |
20816 KB |
Output is correct |
4 |
Correct |
4 ms |
20816 KB |
Output is correct |
5 |
Correct |
4 ms |
20816 KB |
Output is correct |
6 |
Correct |
4 ms |
20816 KB |
Output is correct |
7 |
Correct |
4 ms |
20816 KB |
Output is correct |
8 |
Correct |
3 ms |
20816 KB |
Output is correct |
9 |
Correct |
4 ms |
20944 KB |
Output is correct |
10 |
Correct |
4 ms |
20816 KB |
Output is correct |
11 |
Correct |
4 ms |
20816 KB |
Output is correct |
12 |
Correct |
4 ms |
20816 KB |
Output is correct |
13 |
Correct |
4 ms |
20816 KB |
Output is correct |
14 |
Correct |
5 ms |
20824 KB |
Output is correct |
15 |
Correct |
4 ms |
20860 KB |
Output is correct |
16 |
Correct |
4 ms |
20984 KB |
Output is correct |
17 |
Correct |
4 ms |
20816 KB |
Output is correct |
18 |
Correct |
4 ms |
20816 KB |
Output is correct |
19 |
Correct |
5 ms |
21072 KB |
Output is correct |
20 |
Correct |
5 ms |
20816 KB |
Output is correct |
21 |
Correct |
5 ms |
20816 KB |
Output is correct |
22 |
Correct |
74 ms |
21300 KB |
Output is correct |
23 |
Correct |
75 ms |
21072 KB |
Output is correct |
24 |
Correct |
77 ms |
20948 KB |
Output is correct |
25 |
Correct |
82 ms |
21064 KB |
Output is correct |
26 |
Correct |
74 ms |
20816 KB |
Output is correct |
27 |
Incorrect |
6 ms |
20816 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
20816 KB |
Output is correct |
2 |
Correct |
4 ms |
20816 KB |
Output is correct |
3 |
Correct |
5 ms |
20816 KB |
Output is correct |
4 |
Correct |
4 ms |
20816 KB |
Output is correct |
5 |
Correct |
4 ms |
20816 KB |
Output is correct |
6 |
Correct |
4 ms |
20816 KB |
Output is correct |
7 |
Correct |
4 ms |
20816 KB |
Output is correct |
8 |
Correct |
3 ms |
20816 KB |
Output is correct |
9 |
Correct |
4 ms |
20944 KB |
Output is correct |
10 |
Correct |
4 ms |
20816 KB |
Output is correct |
11 |
Correct |
4 ms |
20816 KB |
Output is correct |
12 |
Correct |
4 ms |
20816 KB |
Output is correct |
13 |
Correct |
4 ms |
20816 KB |
Output is correct |
14 |
Correct |
5 ms |
20824 KB |
Output is correct |
15 |
Correct |
4 ms |
20860 KB |
Output is correct |
16 |
Correct |
4 ms |
20984 KB |
Output is correct |
17 |
Correct |
4 ms |
20816 KB |
Output is correct |
18 |
Correct |
4 ms |
20816 KB |
Output is correct |
19 |
Correct |
5 ms |
21072 KB |
Output is correct |
20 |
Correct |
5 ms |
20816 KB |
Output is correct |
21 |
Correct |
5 ms |
20816 KB |
Output is correct |
22 |
Correct |
74 ms |
21300 KB |
Output is correct |
23 |
Correct |
75 ms |
21072 KB |
Output is correct |
24 |
Correct |
77 ms |
20948 KB |
Output is correct |
25 |
Correct |
82 ms |
21064 KB |
Output is correct |
26 |
Correct |
74 ms |
20816 KB |
Output is correct |
27 |
Correct |
481 ms |
60268 KB |
Output is correct |
28 |
Correct |
509 ms |
58296 KB |
Output is correct |
29 |
Correct |
479 ms |
57960 KB |
Output is correct |
30 |
Correct |
508 ms |
58296 KB |
Output is correct |
31 |
Correct |
415 ms |
51892 KB |
Output is correct |
32 |
Correct |
530 ms |
60596 KB |
Output is correct |
33 |
Correct |
459 ms |
59576 KB |
Output is correct |
34 |
Correct |
467 ms |
57532 KB |
Output is correct |
35 |
Correct |
4 ms |
20816 KB |
Output is correct |
36 |
Incorrect |
27 ms |
24552 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |