# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
49140 | BThero | Circle selection (APIO18_circle_selection) | C++17 | 3038 ms | 41480 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Why am I so stupid? :c
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
typedef long long ll;
using namespace std;
struct circle {
int x, y, r, id;
circle() {
x = y = r = id = 0;
}
} arr[300005];
map < ll, vector <int> > mm;
int ans[300005];
int u[300005];
int n, cur;
int block;
bool inter(circle a, circle b) {
ll dist = (a.x - b.x) * 1ll * (a.x - b.x) + (a.y - b.y) * 1ll * (a.y - b.y);
return dist <= (a.r + b.r) * 1ll * (a.r + b.r);
}
bool cmp(circle a, circle b) {
if (a.r == b.r) {
return a.id < b.id;
}
return a.r > b.r;
}
ll f(int x, int y) {
return x * (ll)2e9 + y;
}
void divIntoBlocks(int st) {
mm.clear();
for (int i = st; i <= n; ++i) {
if (ans[arr[i].id] == arr[i].id) {
mm[f(arr[i].x / block, arr[i].y / block)].pb(i);
}
}
}
void solve() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d %d %d", &arr[i].x, &arr[i].y, &arr[i].r);
arr[i].id = i;
}
sort(arr + 1, arr + n + 1, cmp);
for (int i = 1; i <= n; ++i) {
ans[i] = i;
}
vector <int> vv;
for (int i = 1; i <= n; ++i) {
if (ans[arr[i].id] != arr[i].id) {
continue;
}
if (block == 0 || arr[i].r * 10ll <= block) {
block = arr[i].r;
divIntoBlocks(i + 1);
}
int cx = arr[i].x / block;
int cy = arr[i].y / block;
for (int x = cx - 2; x <= cx + 2; ++x) {
for (int y = cy - 2; y <= cy + 2; ++y) {
ll cur = f(x, y);
auto P = mm.find(cur);
vv.clear();
if (P != mm.end()) {
for (int it : P -> se) {
if (inter(arr[i], arr[it])) {
ans[arr[it].id] = arr[i].id;
}
else {
vv.pb(it);
}
}
P -> se = vv;
}
}
}
/*
for (int j = i + 1; j <= n; ++j) {
if (ans[arr[j].id] == arr[j].id) {
if (inter(arr[i], arr[j])) {
ans[arr[j].id] = arr[i].id;
}
}
}
*/
}
for (int i = 1; i <= n; ++i) {
printf("%d ", ans[i]);
}
}
int main() {
#ifdef BThero
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // BThero
int tt = 1;
while (tt--) {
solve();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |