#include<bits/stdc++.h>
#define MAXN 300007
using namespace std;
int n,par[MAXN],cnt;
long long x[MAXN],y[MAXN],r[MAXN];
pair<int,int> p[MAXN];
map<int,int> mp;
vector<int> w;
int tree[4*MAXN];
void update(int v,int l,int r,int ll,int rr,int val){
if(ll>rr)return;
if(l==ll and r==rr){
tree[v]=val;
}else{
int tt=(l+r)/2;
if(tree[v]!=0)tree[2*v]=tree[2*v+1]=tree[v];
update(2*v,l,tt,ll,min(tt,rr),val);
update(2*v+1,tt+1,r,max(tt+1,ll),rr,val);
}
}
int getpos(int v,int l,int r,int pos){
if(l==r)return tree[v];
int tt=(l+r)/2;
if(tree[v]!=0)tree[2*v]=tree[2*v+1]=tree[v];
if(pos<=tt)return getpos(2*v,l,tt,pos);
return getpos(2*v+1,tt+1,r,pos);
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i]>>r[i];
w.push_back(x[i]-r[i]);
w.push_back(x[i]+r[i]);
p[i]={r[i],-i};
}
sort(w.begin(),w.end());
for(int i=0;i<w.size();i++){
if(i==0 or w[i]!=w[i-1])cnt++;
mp[w[i]]=cnt;
}
sort(p+1,p+n+1);
for(int i=n;i>=1;i--){
int curr=-p[i].second;
int e=getpos(1,1,cnt,mp[x[curr]-r[curr]]);
if(e!=0){
par[curr]=e; continue;
}
e=getpos(1,1,cnt,mp[x[curr]+r[curr]]);
if(e!=0){
par[curr]=e; continue;
}
par[curr]=curr;
update(1,1,cnt,mp[x[curr]-r[curr]],mp[x[curr]+r[curr]],curr);
}
for(int i=1;i<=n;i++){
cout<<par[i]<<" ";
}
cout<<"\n";
return 0;
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:51:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int i=0;i<w.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
375 ms |
87840 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
398 ms |
90052 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |