#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
const ll N=3e5+5;
ll n;
ll x[N],y[N],r[N];
vector<ll>adj[N],ans(N,0);
vector<bool>used(N,0);
ll dist(ll i,ll j){
return abs(x[i]-x[j])*abs(x[i]-x[j])+abs(y[i]-y[j])*abs(y[i]-y[j]);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n;
vector<pair<ll,ll>>v;
bool Y=true;
for(ll i=1;i<=n;i++){
cin>>x[i]>>y[i]>>r[i];
v.pb({-r[i],i});
Y&=(y[i]==0);
}
sort(all(v));
/*
if(n<=5000){
for(ll i=1;i<=n;i++){
for(ll j=i+1;j<=n;j++){
if(dist(i,j)<=(r[i]+r[j])*(r[i]+r[j])){
adj[i].pb(j);
adj[j].pb(i);
}
}
}
for(auto [R,i]:v){
if(ans[i]>0) continue;
ans[i]=i;
for(ll j:adj[i]){
if(ans[j]==0) ans[j]=i;
}
}
for(ll i=1;i<=n;i++){
cout<<ans[i]<<' ';
}
return 0;
}
*/
if(Y){
set<pair<ll,ll>>L,R;
for(ll i=1;i<=n;i++){
L.insert({x[i]-r[i],i});
R.insert({x[i]+r[i],i});
}
vector<ll>del;
for(auto [ra,i]:v){
if(ans[i]>0) continue;
del.clear();
auto it=L.lower_bound({x[i]-r[i],0});
while(it!=L.end()&&it->ff<=x[i]+r[i]){
del.pb(it->ss);
it++;
}
auto it1=R.lower_bound({x[i]-r[i],0});
while(it1!=R.end()&&it1->ff<=x[i]+r[i]){
del.pb(it1->ss);
it1++;
}
for(auto j:del){
if(ans[j]==0){
ans[j]=i;
L.erase({x[j]-r[j],j});
R.erase({x[j]+r[j],j});
}
}
}
for(ll i=1;i<=n;i++){
cout<<ans[i]<<' ';
}
cout<<"\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
15196 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
751 ms |
70072 KB |
Output is correct |
2 |
Correct |
791 ms |
72168 KB |
Output is correct |
3 |
Correct |
742 ms |
75196 KB |
Output is correct |
4 |
Correct |
765 ms |
76016 KB |
Output is correct |
5 |
Correct |
607 ms |
66752 KB |
Output is correct |
6 |
Correct |
537 ms |
66184 KB |
Output is correct |
7 |
Correct |
533 ms |
67228 KB |
Output is correct |
8 |
Correct |
513 ms |
66548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
15196 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
82 ms |
25196 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
15196 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
15196 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |