#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define in insert
#define pb push_back
#define ppb pop_back()
#define d3 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define cans cout << ans << "\n";
#define yes cout << "Yes" << "\n";
#define no cout << "No" << "\n";
#define pll pair<ll,ll>
#define lin cout << "\n";
#define sqr 340
#define mod 1000000007
#define mid ((l+r)/2)
#define lc (2*n)
#define rc (2*n+1)
using namespace std;
ll fp(ll x , ll y)
{
if(y==0)
return 1;
ll z = fp(x,y/2);
if(y&1)
return z*z*x;
else
return z*z;
}
int sqrot(ll x)
{
int l = 0 , r = INT_MAX;
while(l<=r)
{
if(mid*mid>=x)
r=mid-1;
else
l=mid+1;
}
return r+1;
}
ll cel(ll x , ll y)
{
return x/y + bool(x%y);
}
string tb(ll x)
{
string s = "";
while(x>0)
{
if(x&1)
s+='1';
else
s+='0';
x/=2;
}
while(s.size()<60)
s+='0';
return s;
}
ll fb(string s)
{
ll x = 0;
ll c = 1;
for(int8_t i = 0 ; 60>i ; i++)
{
if(s[i]=='1')
x+=c;
c*=2;
}
return x;
}
ll n;
ll x[300009] , y[300009] , r[300009] , t[300009] , ans[300009];
set<ll> sx , sy;
map<ll,set<pll>> mpx , mpy;
set<pll> s;
int main()
{
memset(t,-1,sizeof(t));
cin >> n;
for(int i = 0 ; n>i ; i++)
{
cin >> x[i] >> y[i] >> r[i];
sx.in(x[i]);
sy.in(y[i]);
mpx[x[i]].in({y[i],i});
mpy[y[i]].in({x[i],i});
s.in({r[i],-i});
}
for(int i = 0 ; n>i ; i++)
{
auto itx = sx.upper_bound(x[i]);
if(itx!=sx.end())
{
auto it = mpx[*itx].upper_bound({y[i],-1});
if(it!=mpx[*itx].end())
{
ll c = it->S;
if(c==i)
{
it++;
if(it!=mpx[*itx].end())
c=it->S;
else
it--;
}
ll d1 = (x[i]-x[c])*(x[i]-x[c]) + (y[i]-y[c])*(y[i]-y[c]);
ll d2 = (r[i]+r[c])*(r[i]+r[c]);
if(d1<=d2&&c!=i)
t[i]=c;
}
if(it!=mpx[*itx].begin())
{
it--;
ll c = it->S;
if(c==i&&it!=mpx[*itx].begin())
{
it--;
c=it->S;
}
ll d1 = (x[i]-x[c])*(x[i]-x[c]) + (y[i]-y[c])*(y[i]-y[c]);
ll d2 = (r[i]+r[c])*(r[i]+r[c]);
if(d1<=d2&&c!=i)
t[i]=c;
}
}
if(itx!=sx.begin())
{
itx--;
auto it = mpx[*itx].upper_bound({y[i],-1});
if(it!=mpx[*itx].end())
{
ll c = it->S;
if(c==i)
{
it++;
if(it!=mpx[*itx].end())
c=it->S;
else
it--;
}
ll d1 = (x[i]-x[c])*(x[i]-x[c]) + (y[i]-y[c])*(y[i]-y[c]);
ll d2 = (r[i]+r[c])*(r[i]+r[c]);
if(d1<=d2&&c!=i)
t[i]=c;
}
if(it!=mpx[*itx].begin())
{
it--;
ll c = it->S;
if(c==i&&it!=mpx[*itx].begin())
{
it--;
c=it->S;
}
ll d1 = (x[i]-x[c])*(x[i]-x[c]) + (y[i]-y[c])*(y[i]-y[c]);
ll d2 = (r[i]+r[c])*(r[i]+r[c]);
if(d1<=d2&&c!=i)
t[i]=c;
}
}
if(itx!=sx.begin())
{
itx--;
auto it = mpx[*itx].upper_bound({y[i],-1});
if(it!=mpx[*itx].end())
{
ll c = it->S;
if(c==i)
{
it++;
if(it!=mpx[*itx].end())
c=it->S;
else
it--;
}
ll d1 = (x[i]-x[c])*(x[i]-x[c]) + (y[i]-y[c])*(y[i]-y[c]);
ll d2 = (r[i]+r[c])*(r[i]+r[c]);
if(d1<=d2&&c!=i)
t[i]=c;
}
if(it!=mpx[*itx].begin())
{
it--;
ll c = it->S;
if(c==i&&it!=mpx[*itx].begin())
{
it--;
c=it->S;
}
ll d1 = (x[i]-x[c])*(x[i]-x[c]) + (y[i]-y[c])*(y[i]-y[c]);
ll d2 = (r[i]+r[c])*(r[i]+r[c]);
if(d1<=d2&&c!=i)
t[i]=c;
}
}
auto ity = sy.upper_bound(y[i]);
if(ity!=sy.end())
{
auto it = mpy[*ity].upper_bound({x[i],-1});
if(it!=mpy[*ity].end())
{
ll c = it->S;
if(c==i)
{
it++;
if(it!=mpy[*ity].end())
c=it->S;
else
it--;
}
ll d1 = (x[i]-x[c])*(x[i]-x[c]) + (y[i]-y[c])*(y[i]-y[c]);
ll d2 = (r[i]+r[c])*(r[i]+r[c]);
if(d1<=d2&&c!=i)
t[i]=c;
}
if(it!=mpy[*ity].begin())
{
it--;
ll c = it->S;
if(c==i&&it!=mpy[*ity].begin())
{
it--;
c=it->S;
}
ll d1 = (x[i]-x[c])*(x[i]-x[c]) + (y[i]-y[c])*(y[i]-y[c]);
ll d2 = (r[i]+r[c])*(r[i]+r[c]);
if(d1<=d2&&c!=i)
t[i]=c;
}
}
if(ity!=sy.begin())
{
ity--;
auto it = mpy[*ity].upper_bound({x[i],-1});
if(it!=mpy[*ity].end())
{
ll c = it->S;
if(c==i)
{
it++;
if(it!=mpy[*ity].end())
c=it->S;
else
it--;
}
ll d1 = (x[i]-x[c])*(x[i]-x[c]) + (y[i]-y[c])*(y[i]-y[c]);
ll d2 = (r[i]+r[c])*(r[i]+r[c]);
if(d1<=d2&&c!=i)
t[i]=c;
}
if(it!=mpy[*ity].begin())
{
it--;
ll c = it->S;
if(c==i&&it!=mpy[*ity].begin())
{
it--;
c=it->S;
}
ll d1 = (x[i]-x[c])*(x[i]-x[c]) + (y[i]-y[c])*(y[i]-y[c]);
ll d2 = (r[i]+r[c])*(r[i]+r[c]);
if(d1<=d2&&c!=i)
t[i]=c;
}
}
if(ity!=sy.begin())
{
ity--;
auto it = mpy[*ity].upper_bound({x[i],-1});
if(it!=mpy[*ity].end())
{
ll c = it->S;
if(c==i)
{
it++;
if(it!=mpy[*ity].end())
c=it->S;
else
it--;
}
ll d1 = (x[i]-x[c])*(x[i]-x[c]) + (y[i]-y[c])*(y[i]-y[c]);
ll d2 = (r[i]+r[c])*(r[i]+r[c]);
if(d1<=d2&&c!=i)
t[i]=c;
}
if(it!=mpy[*ity].begin())
{
it--;
ll c = it->S;
if(c==i&&it!=mpy[*ity].begin())
{
it--;
c=it->S;
}
ll d1 = (x[i]-x[c])*(x[i]-x[c]) + (y[i]-y[c])*(y[i]-y[c]);
ll d2 = (r[i]+r[c])*(r[i]+r[c]);
if(d1<=d2&&c!=i)
t[i]=c;
}
}
}
//for(int i = 0 ; n>i ; i++)
//cout << t[i]+1 << " ";
while(!s.empty())
{
auto it = s.end();
it--;
ll c = -it->S;
s.erase(it);
ans[c]=c+1;
if(t[c]==-1)
continue;
ans[t[c]]=c+1;
s.erase(s.find({r[t[c]],-t[c]}));
}
for(int i = 0 ; n>i ; i++)
cout << ans[i] << " ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8600 KB |
Output is correct |
5 |
Execution timed out |
3064 ms |
8540 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1706 ms |
224484 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8540 KB |
Output is correct |
2 |
Incorrect |
743 ms |
58324 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2778 ms |
154956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8600 KB |
Output is correct |
5 |
Execution timed out |
3064 ms |
8540 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8600 KB |
Output is correct |
5 |
Execution timed out |
3064 ms |
8540 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |