#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();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
268 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
24 ms |
5292 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
368 ms |
28984 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
25 ms |
5580 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
268 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
268 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |