이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
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(auto itr = g[j].begin();itr != g[j].end();++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;
}
컴파일 시 표준 에러 (stderr) 메시지
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) {
| ~~^~~~~~~~~~~
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:70:13: warning: unused variable 'y' [-Wunused-variable]
70 | long long y = pts[i].second.second;
| ^
circle_selection.cpp:71:13: warning: unused variable 'r' [-Wunused-variable]
71 | long long r = pts[i].first.first;
| ^
# | 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... |