This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define int long long
#define pi pair<int, int >
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define mset multiset
#define F first
#define S second
using namespace std;
struct circle {
int x, y, r;
void init() {cin >> x >> y >> r;}
};
circle C[300001];
int n, mx, ans[300001];
map<pair<int, int>, vector<int>> mp;
bool check(int i, int j) {
int d = (C[i].x - C[j].x) * (C[i].x - C[j].x);
d += (C[i].y - C[j].y) * (C[i].y - C[j].y);
return (d <= (C[i].r + C[j].r) * (C[i].r + C[j].r));
}
void build() {mp.clear();
for (int i = 1; i <= n; i++) if (!ans[i]) mp[{C[i].x/mx, C[i].y/mx}].pb(i);
}
bool cmp(int a, int b) {return (C[a].r > C[b].r || (C[a].r == C[b].r && a < b));}
void solve() {
cin >> n; for (int i = 1; i <= n; i++)
{C[i].init(); C[i].x += 1e9; C[i].y += 1e9; mx = max(mx, C[i].r);}
vector<int> v(n); iota(all(v), 1); sort(all(v), cmp); build();
for (int i: v) {
if (ans[i]) continue;
if (C[i].r <= mx / 2) {mx /= 2; build();}
for (int j = C[i].x/mx-2; j <= C[i].x/mx+2; j++)
for (int k = C[i].y/mx-2; k <= C[i].y/mx+2; k++) {
if (!mp.count({j, k})) continue;
for (int l: mp[{j, k}]) if (!ans[l] && check(i, l)) ans[l] = i;
}
}
for (int i = 1; i <= n; i++) cout << ans[i] << ' ';
}
signed main() {IOS solve(); return 0;}
# | 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... |