This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
const char nl = '\n';
void fastIO() {
ios::sync_with_stdio(false);
cin.tie(0);
}
int main() {
fastIO();
int N;
cin>>N;
vector<ii> cr(N);
for (int i = 0; i < N; i++) {
int x, y, r;
cin>>x>>y>>r;
cr[i] = {x, r};
}
multiset<ii> lpos; // {lp, id}
multiset<ii> rpos; // {rp, id}
multiset<ii> have; // {r, -id]}
for (int i = 0; i < N; i++) {
int x = cr[i].fi;
int r = cr[i].se;
lpos.insert({x - r, i});
rpos.insert({x + r, i});
have.insert({r, -i});
}
vi par(N, -1);
int rem = N;
while (rem != 0) {
auto it = --have.end();
int id = -(*it).se; // id of current circle
int x = cr[id].fi;
int r = cr[id].se;
int lp = x - r;
int rp = x + r;
// cout<<"at "<<id<<endl;
// cout<<"lp, rp: "<<lp<<" "<<rp<<endl;
// find all circles with lp[i], rp[i] in [lp, rp]
set<int> tr; // id of circles to remove
auto it2 = lpos.lower_bound({lp, -1});
while ((it2 != lpos.end()) && ((*it2).fi <= rp)) {
tr.insert((*it2).se);
it2++;
}
auto it3 = rpos.lower_bound({lp, -1});
while ((it3 != rpos.end()) && ((*it3).fi <= rp)) {
tr.insert((*it3).se);
it3++;
}
for (int x : tr) {
par[x] = id;
rem--;
int xt = cr[x].fi;
int rt = cr[x].se;
lpos.erase({xt - rt, x});
rpos.erase({xt + rt, x});
have.erase({rt, -x});
}
// cout<<id<<": "<<rem<<endl;
}
// cout<<"ANSWER: ";
for (int x : par)
cout<<(x + 1)<<" ";
cout<<endl;
}
# | 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... |