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;
#define ll long long
#define ff first
#define ss second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define N 300005
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
int x[N], y[N], r[N];
int lr = 2'000'000'002;
int ans[N];
int n;
vector<pair<int, int> > v;
map<pair<int, int>, vector<int> > id;
inline ll pw(ll a){
return a * a;
}
bool check(int i, int j){
return pw(x[i] - x[j]) + pw(y[i] - y[j]) <= pw(r[i] + r[j]);
}
inline int divv(int a, int b){
return a / b - (a < 0 && a % b != 0);
}
void reset(int r){
id.clear();
for(int i = 1; i <= n; ++i){
if(ans[i]) continue;
int xx = divv(x[i], r);
int yy = divv(y[i], r);
id[{xx, yy}].push_back(i);
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i = 1; i <= n; ++i){
cin>>x[i]>>y[i]>>r[i];
v.push_back({-r[i], i});
}
sort(v.begin(), v.end());
for(auto& w : v){
if(ans[w.ss]) continue;
if(lr >= 2 * r[w.ss])
reset(lr = r[w.ss]);
int xx = divv(x[w.ss], lr);
int yy = divv(y[w.ss], lr);
for(int dx = -2; dx <= 2; ++dx){
for(int dy = -2; dy <= 2; ++dy){
auto it = id.find({xx + dx, yy + dy});
if(it == id.end()) continue;
for(int i = 0; i < it -> ss.size(); ++i){
if(check(it -> ss[i], w.ss)){
ans[it -> ss[i]] = w.ss;
swap(it -> ss[i], it -> ss.back());
it -> ss.pop_back();
--i;
}
}
if(it -> ss.empty())
id.erase(it);
}
}
}
for(int i = 1; i <= n; ++i)
cout<<ans[i]<<' ';
}
Compilation message (stderr)
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:66:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < it -> ss.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... |