using namespace std;
#include <iostream>
#include <vector>
#include <algorithm>
#define MAXN 300005
typedef long long ll;
typedef pair<ll,ll> pll;
int N,vis[MAXN],ans[MAXN];
// current unit circle length
long long gl = 1e18;
vector<pair<pair<ll,int>,pll>> pts;
vector<ll> xs;
vector<vector<pair<ll,int>>> g;
int get(long long x) {
x /= gl;
return lower_bound(xs.begin(),xs.end(),x) - xs.begin();
}
long long sq(long long x) {
return x * x;
}
bool check(int a,int b) {
return sq(pts[a].second.first - pts[b].second.first) + sq(pts[a].second.second - pts[b].second.second) <= sq(pts[a].first.first + pts[b].first.first);
}
void reconstruct(long long nl) {
// cout << "BEGIN RECONSTRUCTION!" << endl;
gl = nl;
g.clear();
xs.clear();
for(auto [a,b] : pts) {
xs.push_back(b.first / nl);
}
sort(xs.begin(),xs.end());
xs.resize(unique(xs.begin(),xs.end()) - xs.begin());
g = vector<vector<pair<ll,int>>>(xs.size(),vector<pair<ll,int>>());
for(int i = 0;i < N;++i) {
if(!vis[i]) g[get(pts[i].second.first)].push_back({pts[i].second.second,i});
}
for(int i = 0;i < xs.size();++i) {
sort(g[i].begin(),g[i].end());
}
return;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> N;
for(int i = 0;i < N;++i) {
long long x,y,r;
cin >> x >> y >> r;
pts.push_back({{r,i},{x + 1e9,y + 1e9}});
}
sort(pts.begin(),pts.end(),[&](auto a,auto b) {return make_pair(-a.first.first,a.first.second) < make_pair(-b.first.first,b.first.second);});
for(int i = 0;i < N;++i) {
if(vis[i]) continue;
// cout << "TERMINATOR " << i << " " << (pts[i].first.second + 1) << endl;
if(pts[i].first.first * 2 <= gl) {
reconstruct(pts[i].first.first);
}
int x = get(pts[i].second.first);
long long y = pts[i].second.second;
long long r = pts[i].first.first;
int index = pts[i].first.second;
for(int j = max(0,x - 2);j <= min(x + 2,(int)xs.size() - 1);++j) {
auto itr = lower_bound(g[j].begin(),g[j].end(),make_pair(y - r,-1));
for(;itr != g[j].end() && itr -> first - y <= r;++itr) {
if(check(i,itr -> second)) {
if(!vis[itr -> second]) vis[itr -> second] = index + 1;
}
}
}
}
for(int i = 0;i < N;++i) {
ans[pts[i].first.second] = vis[i];
}
for(int i = 0;i < N;++i) {
cout << ans[i] << " \n"[i == N - 1];
}
return 0;
}
Compilation message
circle_selection.cpp: In function 'void reconstruct(long long int)':
circle_selection.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i = 0;i < xs.size();++i) {
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
292 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
182 ms |
34100 KB |
Output is correct |
2 |
Correct |
191 ms |
32176 KB |
Output is correct |
3 |
Correct |
172 ms |
31432 KB |
Output is correct |
4 |
Correct |
180 ms |
32644 KB |
Output is correct |
5 |
Correct |
346 ms |
35060 KB |
Output is correct |
6 |
Correct |
511 ms |
52956 KB |
Output is correct |
7 |
Correct |
440 ms |
44048 KB |
Output is correct |
8 |
Correct |
411 ms |
45600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
253 ms |
17088 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
362 ms |
33964 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
292 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
292 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |