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>
using namespace std;
typedef long long ll;
constexpr int INF = 1e9 + 100, CHK = 2;
struct Circle{
int x, y, r, i, xl, xr;
Circle(){}
bool operator < (const Circle &C) const{
if (r==C.r) return i < C.i;
return r > C.r;
}
}C[300300];
int ans[300300];
int ok(int i, int j){
ll d = (ll)(C[i].x-C[j].x) * (C[i].x-C[j].x) + (ll)(C[i].y-C[j].y) * (C[i].y-C[j].y);
ll r = (ll)(C[i].r + C[j].r) * (C[i].r + C[j].r);
return d <= r;
}
struct Seg{
int sz;
map<int, int> tree[1201200];
map<int, int>::iterator iter0[30], iter[30];
int T[30], buf[30], pt;
void init(int n){
sz = n;
}
void update(int l, int r, int y, int i){
r++;
for (l+=sz, r+=sz;l<r;l>>=1, r>>=1){
if (l&1){
tree[l][y] = i;
l++;
}
if (r&1){
--r;
tree[r][y] = i;
}
}
}
int queryU(int x, int y, int i){
pt = 0;
for (int node=x+sz;node>0;node>>=1){
iter0[pt] = tree[node].lower_bound(y);
iter[pt] = iter0[pt];
T[pt] = node;
buf[pt] = (iter[pt]==tree[T[pt]].end())?INF:iter[pt]->first;
pt++;
}
int ret = i;
for (int _=0;_<CHK;_++){
int idx = min_element(buf, buf+pt) - buf;
if (buf[idx]==INF) break;
if (ok(i, iter[idx]->second)) ret = min(ret, iter[idx]->second);
iter[idx]++;
buf[idx] = (iter[idx]==tree[T[idx]].end())?INF:iter[idx]->first;
}
return ret;
}
int queryD(int i){
for (int i=0;i<pt;i++){
iter[i] = iter0[i];
buf[i] = (iter[i]==tree[T[i]].begin())?(-INF):prev(iter[i])->first;
}
int ret = i;
for (int _=0;_<CHK;_++){
int idx = max_element(buf, buf+pt) - buf;
if (buf[idx]==-INF) break;
iter[idx]--;
if (ok(i, iter[idx]->second)) ret = min(ret, iter[idx]->second);
buf[idx] = (iter[idx]==tree[T[idx]].begin())?(-INF):prev(iter[idx])->first;
}
return ret;
}
}tree;
int calc(int x, int i){
int ret = i;
ret = min(ret, tree.queryU(x, C[i].y, i));
ret = min(ret, tree.queryD(i));
return ret;
}
int main(){
int n;
scanf("%d", &n);
vector<int> X;
for (int i=1;i<=n;i++){
scanf("%d %d %d", &C[i].x, &C[i].y, &C[i].r);
X.push_back(C[i].x - C[i].r);
X.push_back(C[i].x + C[i].r);
C[i].i = i;
}
sort(X.begin(), X.end());
X.erase(unique(X.begin(), X.end()), X.end());
for (int i=1;i<=n;i++){
C[i].xl = lower_bound(X.begin(), X.end(), C[i].x - C[i].r) - X.begin();
C[i].xr = lower_bound(X.begin(), X.end(), C[i].x + C[i].r) - X.begin();
}
sort(C+1, C+n+1);
tree.init(X.size());
for (int i=1;i<=n;i++){
ans[C[i].i] = min(calc(C[i].xl, i), calc(C[i].xr, i));
if (ans[C[i].i]==i) tree.update(C[i].xl, C[i].xr, C[i].y, i);
ans[C[i].i] = C[ans[C[i].i]].i;
}
for (int i=1;i<=n;i++) printf("%d ", ans[i]);
printf("\n");
}
Compilation message (stderr)
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:108:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
108 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
circle_selection.cpp:112:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
112 | scanf("%d %d %d", &C[i].x, &C[i].y, &C[i].r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |