#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
int N;
ll X[300005],Y[300005],R[300005];
ll A[300005],P[300005];
vector<pll> V;
ll h;
set<pll> S;
map<ll, set<pll> > M;
ll r;
int main(){
cin>>N;
for(int i=0;i<N;i++){
cin>>X[i]>>Y[i]>>R[i];
h=max(h,Y[i]);
}
if(false and N<5001){
for(int i=0;i<N;i++)
V.push_back({-R[i],i});
sort(V.begin(),V.end());
for(int i=0;i<N;i++)
P[i]=V[i].second;
//for(int i=0;i<N;i++)cout<<P[i]+1<<" ";cout<<endl;
for(int i=0;i<N;i++)
for(int j=i+1;j<N;j++)
if(
(X[P[i]]-X[P[j]])*(X[P[i]]-X[P[j]])+
(Y[P[i]]-Y[P[j]])*(Y[P[i]]-Y[P[j]])<=
(R[P[i]]+R[P[j]])*(R[P[i]]+R[P[j]])
and !A[P[j]] and !A[P[i]]
)
A[P[j]]=P[i]+1;
for(int i=0;i<N;i++)
cout<<(A[i]?A[i]:(i+1))<<" "; }
else if(false and !h){
for(int i=0;i<N;i++)
V.push_back({-R[i],i});
sort(V.begin(),V.end());
for(int i=0;i<N;i++){
S.insert({X[i]+R[i],i});
S.insert({X[i]-R[i],i});
P[i]=V[i].second;
}
for(int j=0;j<N;j++){
int i=P[j];
if(S.count({X[i]-R[i],i}))
for(auto p=S.lower_bound({X[i]-R[i],-1});p!=S.lower_bound({X[i]+R[i]+1,-1});){
int q=p->second;
A[q]=i+1;
if(p==S.find({X[q]-R[q],q}))
p++;
S.erase(S.find({X[q]-R[q],q}));
if(p==S.find({X[q]+R[q],q}))
p++;
S.erase(S.find({X[q]+R[q],q}));
}
}
for(int i=0;i<N;i++)
cout<<A[i]<<" ";}
else{
r=2*R[0];
for(int i=0;i<N;i++)
M[X[i]].insert({Y[i],i});
for(int i=0;i<N;i++)
if(!A[i]){
auto a=M.lower_bound(X[i]-r);
auto b=M.lower_bound(X[i]+r+1);
for(auto s=a;s!=b;){
auto c=(s->second).lower_bound({Y[i]-r,-1});
auto d=(s->second).lower_bound({Y[i]+r+1,-1});
for(auto p=c;p!=d;){
int j=p->second;
auto q=p;
p++;
if((X[i]-X[j])*(X[i]-X[j])+(Y[i]-Y[j])*(Y[i]-Y[j])<=r*r){
A[j]=i+1;
(s->second).erase(q);
}
}
auto g=s;
s++;
if((g->second).empty())
M.erase(g);
}
}
for(int i=0;i<N;i++)
cout<<A[i]<<" ";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1078 ms |
57240 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1619 ms |
58632 KB |
Output is correct |
2 |
Correct |
1277 ms |
58632 KB |
Output is correct |
3 |
Execution timed out |
3038 ms |
56700 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |