이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define N 100005
using namespace std;
int x[N],y[N],c[N];
int ans[N];
void solve(){
int n;
cin >> n;
vector<int> ord;
for(int i = 1;i<=n;i++){
cin >> x[i] >> y[i] >> c[i];
ord.push_back(i);
}
sort(ord.begin(),ord.end(),[&](int a,int b){
if(c[a] == c[b])
return a < b;
return c[a] > c[b];
});
set<pair<int,int>> sx,sy,sxy,sxxy,sxyy;
for(auto u:ord){
int num = -1;
vector<int> cand;
auto it =sx.lower_bound({x[u],0});
if(it != sx.end()){
cand.push_back(it->second);
}
if(it != sx.begin()){
cand.push_back(prev(it)->second);
}
it =sy.lower_bound({y[u],0});
if(it != sy.end()){
cand.push_back(it->second);
}
if(it != sy.begin()){
cand.push_back(prev(it)->second);
}
it =sxy.lower_bound({x[u] + y[u],0});
if(it != sxy.end()){
cand.push_back(it->second);
}
if(it != sxy.begin()){
cand.push_back(prev(it)->second);
}
it =sxxy.lower_bound({x[u] - y[u],0});
if(it != sxxy.end()){
cand.push_back(it->second);
}
if(it != sxxy.begin()){
cand.push_back(prev(it)->second);
}
it =sxyy.lower_bound({-x[u] + y[u],0});
if(it != sxyy.end()){
cand.push_back(it->second);
}
if(it != sxyy.begin()){
cand.push_back(prev(it)->second);
}
for(auto cc:cand){
// cout << cc << endl;
// cout << u << endl;
long long val1 = (long long)(c[u] + c[cc]) *(c[u] + c[cc]);
long long val2 = (long long)(x[u] - x[cc]) *(x[u] - x[cc])
+ (long long)(y[u] - y[cc]) *(y[u] - y[cc]);
// cout << val1 << ' ' << val2 << endl;
if(val2 <= val1){
if(num == -1 || u < num)
num = cc;
}
}
if(num == -1){
ans[u] = u;
sx.insert({x[u],u});
sy.insert({y[u],u});
sxy.insert({x[u] + y[u],u});
sxxy.insert({x[u] - y[u],u});
sxyy.insert({-x[u] + y[u],u});
}
else ans[u] = num;
}
for(int i = 1;i<=n;i++){
cout << ans[i] << ' ';
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
# | 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... |