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 / gl);
}
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);});
reconstruct(1e18);
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)) {
// cout << (itr -> second) << endl;
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:37:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
37 | for(auto [a,b] : pts) {
| ^
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) {
| ~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
169 ms |
29640 KB |
Output is correct |
2 |
Correct |
169 ms |
29552 KB |
Output is correct |
3 |
Correct |
180 ms |
29392 KB |
Output is correct |
4 |
Correct |
163 ms |
29532 KB |
Output is correct |
5 |
Execution timed out |
3011 ms |
26268 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
92 ms |
9412 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
327 ms |
29520 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |