#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define INF 1e9+7
#define all(x) x.begin(),x.end()
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using pii=pair<int,int>;
using ppi=pair<int,pii>;
using oset=tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;
template<typename T>
void _print(vector<T> x) {cerr<<"{"; for(auto e:x) cerr<<e<<","; cerr<<"}";}
void _print(pii x) {cerr<<"{"<<x.first<<","<<x.second<<"}";}
template<typename T>
void _print(T x) {cerr<<x;}
void dbg() {cerr<<endl;}
template<typename Head,typename... Tail>
void dbg(Head H,Tail... T) {
_print(H);
if(sizeof...(T)) cerr<<",";
else cerr<<"\"]";
dbg(T...);
}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:[\"",dbg(__VA_ARGS__)
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct dt {
ll x,y,r;
int idx;
bool intersect(const dt &aa) {
return abs(aa.x-x)<=r+aa.r;
// return (x-aa.x)*(x-aa.x)+(y-aa.y)*(y-aa.y)<=(r+aa.r)*(r+aa.r);
}
bool operator<(const dt &aa) {
return r<aa.r;
}
};
bool operator>(const dt &aa,const dt &bb) {
if(aa.r==bb.r) return aa.x<bb.x;
return aa.r>bb.r;
}
bool same[5010][5010];
void deebug(vector<dt> ar) {
cout<<"----"<<endl;
int len=ar.size();
for(int i=0;i<len;i++) {
cout<<ar[i].x<<" "<<ar[i].y<<" "<<ar[i].r<<endl;
}
cout<<"===="<<endl;
}
bool cmp2(const dt &l,const dt &r) {
return (l.x-l.r)<(r.x-r.r);
}
bool cmp3(const dt &l,const dt &r) {
return (l.x+l.r)<(r.x+r.r);
}
int main () {
ios::sync_with_stdio(false); cin.tie(0);
int n; cin>>n;
vector<dt> a(n),a2(n),a3(n);
for(int i=0;i<n;i++) cin>>a[i].x>>a[i].y>>a[i].r,a[i].idx=i;
a2=a; a3=a;
sort(all(a),greater<dt>());
sort(all(a2),cmp2);
sort(all(a3),cmp3);
vector<int> toA(n),toA2(n),toA3(n);
vector<int> ans(n,-1);
for(int i=0;i<n;i++) {
toA[a[i].idx]=i;
toA2[a2[i].idx]=i;
toA3[a3[i].idx]=i;
}
for(int i=0;i<n;i++) {
int idx=a[i].idx;
int u=idx;
if(ans[u]!=-1) continue;
ans[u]=u;
int idx2=toA2[idx];
int idx3=toA3[idx];
int p1=lower_bound(all(a2),a[i],cmp2)-begin(a2)-1;
int p2=lower_bound(all(a3),a[i],cmp3)-begin(a3)+1;
while(p1>=0 and a[i].intersect(a3[p1])) {
int v=a3[p1].idx;
if(ans[v]!=-1) break;
ans[v]=u; --p1;
}
while(p2<n and a[i].intersect(a2[p2])) {
int v=a2[p2].idx;
if(ans[v]!=-1) break;
ans[v]=u; ++p2;
}
}
// deebug(a2);
// deebug(a3);
for(int i=0;i<n;i++) cout<<ans[i]+1<<" "; cout<<endl;
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:88:13: warning: unused variable 'idx2' [-Wunused-variable]
88 | int idx2=toA2[idx];
| ^~~~
circle_selection.cpp:89:13: warning: unused variable 'idx3' [-Wunused-variable]
89 | int idx3=toA3[idx];
| ^~~~
circle_selection.cpp:106:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
106 | for(int i=0;i<n;i++) cout<<ans[i]+1<<" "; cout<<endl;
| ^~~
circle_selection.cpp:106:47: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
106 | for(int i=0;i<n;i++) cout<<ans[i]+1<<" "; cout<<endl;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
349 ms |
35956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
292 ms |
36716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |