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;
const int maxn = 3e5+5;
const int INF = 1e9+5;
pair<int, int> pt[maxn];
bool cmpx(int a, int b){
return pt[a].first < pt[b].first;
}
bool cmpy(int a, int b){
return pt[a].second < pt[b].second;
}
int n;
int st[4*maxn], Lx[4*maxn], Rx[4*maxn], Ly[4*maxn], Ry[4*maxn];
int pid[4*maxn];
int pos[maxn];
int removed[maxn];
int R[maxn];
bool cmpr(int a, int b){
return R[a] != R[b] ? R[a] > R[b] : a < b;
}
bool check(int a, int b){
return 1LL*(pt[a].first - pt[b].first)*(pt[a].first - pt[b].first) + 1LL*(pt[a].second - pt[b].second)*(pt[a].second - pt[b].second) - 1LL*(R[a] + R[b])*(R[a] + R[b]) <= 0;
}
void build(vector<int> vec, int dep, int id){
Lx[id] = Ly[id] = INF;
if(vec.empty())return;
sort(vec.begin(), vec.end(), dep&1 ? cmpx : cmpy);
int mid = vec.size()/2;
pid[id] = vec[mid];
pos[vec[mid]] = id;
vector<int> v1, v2;
for(int i = 0; i < vec.size(); i++){
if(i < mid)v1.push_back(vec[i]);
if(i > mid)v2.push_back(vec[i]);
}
for(auto v: vec){
st[id] = max(st[id], R[v]);
Lx[id] = min(Lx[id], pt[v].first);
Ly[id] = min(Ly[id], pt[v].second);
Rx[id] = max(Rx[id], pt[v].first);
Ry[id] = max(Ry[id], pt[v].second);
}
build(v1, dep^1, id<<1);
build(v2, dep^1, id<<1|1);
}
void recalc(int id){
st[id] = max(st[id<<1], st[id<<1|1]);
Lx[id] = min(Lx[id<<1], Lx[id<<1|1]);
Ly[id] = min(Ly[id<<1], Ly[id<<1|1]);
Rx[id] = max(Rx[id<<1], Rx[id<<1|1]);
Ry[id] = max(Ry[id<<1], Ry[id<<1|1]);
if(pid[id]){
st[id] = max(st[id], R[pid[id]]);
Lx[id] = min(Lx[id], pt[pid[id]].first);
Ly[id] = min(Ly[id], pt[pid[id]].second);
Rx[id] = max(Rx[id], pt[pid[id]].first);
Ry[id] = max(Ry[id], pt[pid[id]].second);
}
}
void remove(int x){
int id = pos[x];
pid[id] = 0;
while(id){
recalc(id);
id >>= 1;
}
}
void search(int x, int dep, int id){
if(pid[id]){
if(check(x, pid[id])){
removed[pid[id]] = x;
remove(pid[id]);
}
}
if(st[id<<1] && (dep&1 ? (pt[x].first < Rx[id<<1] || pt[x].first - Rx[id<<1] <= R[x] + st[id<<1]) :
(pt[x].second < Ry[id<<1] || pt[x].second - Ry[id<<1] <= R[x] + st[id<<1])))search(x, dep^1, id<<1);
if(st[id<<1|1] && (dep&1 ? (pt[x].first > Lx[id<<1|1] || Lx[id<<1|1] - pt[x].first <= R[x] + st[id<<1|1]) :
(pt[x].second > Ly[id<<1|1] || Ly[id<<1|1] - pt[x].second <= R[x] + st[id<<1|1])))search(x, dep^1, id<<1|1);
}
vector<int> bad;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
vector<int> vec(n);
iota(vec.begin(), vec.end(), 1);
for(int i = 1; i <= n; i++){
cin >> pt[i].first >> pt[i].second >> R[i];
}
build(vec, 0, 1);
sort(vec.begin(), vec.end(), cmpr);
for(auto v: vec){
if(removed[v])continue;
search(v, 0, 1);
}
for(int i = 1; i <= n; i++)cout << removed[i] << " ";
}
Compilation message (stderr)
circle_selection.cpp: In function 'void build(std::vector<int>, int, int)':
circle_selection.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int i = 0; i < vec.size(); i++){
| ~~^~~~~~~~~~~~
# | 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... |