#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define pb push_back
#define emb emplace_back
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define sp << " " <<
#define N 2000
#define inf 1e9
typedef pair<int,int> ii;
typedef tuple<int,int,int> iii;
int dsu[N+5];
int find(int x){
if(dsu[x]<0) return x;
return dsu[x]=find(dsu[x]);
}
void comb(int x,int y){
x=find(x);y=find(y);
if(x==y) return;
dsu[y]=x;
}
void solve(){
memset(dsu,-1,sizeof(dsu));
int n,q,w,h;
cin >> n >> q >> w >> h;
vector<iii> circle,edge,query;
for(int i=0;i<n;i++){
int x,y,z;
cin >> x >> y >> z;
circle.emb(x,y,z);
}
for(int i=0;i<q;i++){
int x,y;
cin >> x >> y;
query.emb(x,y-1,i);
}
for(int i=0;i<n;i++){
int x,y,r;
tie(x,y,r)=circle[i];
edge.emb(x-r,i,n+0);
edge.emb(y-r,i,n+1);
edge.emb(w-x-r,i,n+2);
edge.emb(h-y-r,i,n+3);
for(int j=i+1;j<n;j++){
int x1,y1,r1;
tie(x1,y1,r1)=circle[j];
edge.emb((int)sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y))-r-r1,i,j);
}
}
sort(all(edge));
sort(all(query));
int j=0;
vector<int> ans[q];
for(auto [r,st,i]:query){
while(get<0>(edge[j])<2*r){
comb(get<1>(edge[j]),get<2>(edge[j]));
j++;
}
int a=st,b=(st+1)%4,c=(st+2)%4,d=(st+3)%4;
ans[i].pb(a);
if(find(n+a)!=find(n+b)){
if(find(n+b)!=find(n+d) && find(n+b)!=find(n+c))
ans[i].pb(b);
if(find(n+b)!=find(n+d) && find(n+a)!=find(n+c) && find(n+c)!=find(n+d))
ans[i].pb(c);
if(find(n+a)!=find(n+c) && find(n+a)!=find(n+d))
ans[i].pb(d);
}
}
for(int i=0;i<q;i++){
sort(all(ans[i]));
for(int j:ans[i])
cout << j+1;
cout << "\n";
}
}
int32_t main(){
cout << fixed << setprecision(9);
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int test=1;
//~ cin >> test;
while(test--){
solve();
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |