#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define N 2005
struct A{
long long a,b,r,st;
bool operator<(const A& o)const{
return r<o.r;
}
};
struct B{
long long r,e,id;
bool operator<(const B& o)const{
return r<o.r;
}
};
int p[N],bit[N],ans[100005];
long long x[N],y[N],r[N];
vector<A> edge;
vector<B> op;
bitset<20> vis,ok[5];
int fp(int v){return v==p[v]?v:p[v]=fp(p[v]);}
int dis(int i,int j){
long long a=x[i]-x[j],b=y[i]-y[j],c=a*a+b*b,ll,rr,mid,d;
ll=1,rr=1e9;
while(ll<=rr){
mid=(ll+rr)/2;
if(mid*mid<=c)d=mid,ll=mid+1;
else rr=mid-1;
}
return d-r[i]-r[j];
}
void add(int id){
auto [a,b,r,st]=edge[id];
if(!st){
bit[fp(a)]|=bit[fp(b)];
p[fp(b)]=fp(a);
}
else bit[fp(a)]|=st;
if(!vis[bit[fp(a)]]){
int i,j;
b=bit[fp(a)];
vis[bit[fp(a)]]=true;
for(i=0;i<4;i++){
if((b&(1<<i))&&(b&(1<<((i+1)%4)))){
for(j=0;j<4;j++){
if(i!=j)ok[i+1][j+1]=ok[j+1][i+1]=false;
}
}
}
if((b&1)&&(b&4))ok[1][4]=ok[4][1]=ok[1][3]=ok[3][1]=ok[4][2]=ok[2][4]=ok[2][3]=ok[3][2]=false;
if((b&2)&&(b&8))ok[1][2]=ok[2][1]=ok[1][3]=ok[3][1]=ok[4][2]=ok[2][4]=ok[4][3]=ok[3][4]=false;
}
}
int main(){
int n,m,w,h,i,j,now,val;
long long radius,e;
scanf("%d %d %d %d",&n,&m,&w,&h);
iota(p,p+n+1,0);
for(i=1;i<=n;i++){
scanf("%lld %lld %lld",&x[i],&y[i],&r[i]);
}
for(i=1;i<=n;i++){
for(j=i+1;j<=n;j++){
edge.push_back({i,j,dis(i,j),0});
}
}
for(i=1;i<=n;i++){
edge.push_back({i,0,x[i]-r[i],1});
edge.push_back({i,0,y[i]-r[i],2});
edge.push_back({i,0,w-x[i]-r[i],4});
edge.push_back({i,0,h-y[i]-r[i],8});
}
for(i=1;i<=4;i++)for(j=1;j<=4;j++)ok[i][j]=true;
sort(edge.begin(),edge.end());
for(i=1;i<=m;i++)scanf("%lld %lld",&radius,&e),op.push_back({2*radius,e,i});
sort(op.begin(),op.end());
now=0;
for(auto [rad,e,id]:op){
while(now<edge.size()&&edge[now].r<rad)add(now++);
val=0;
for(i=1;i<=4;i++)if(ok[e][i])val=val*10+i;
ans[id]=val;
}
for(i=1;i<=m;i++)printf("%d\n",ans[i]);
return 0;
}
/*
5 3
16 11
11 8 1
6 10 1
7 3 2
10 4 1
15 5 1
1 1
2 2
2 1
*/
Compilation message
park.cpp: In function 'int main()':
park.cpp:88:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<A>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | while(now<edge.size()&&edge[now].r<rad)add(now++);
| ~~~^~~~~~~~~~~~
park.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | scanf("%d %d %d %d",&n,&m,&w,&h);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
69 | scanf("%lld %lld %lld",&x[i],&y[i],&r[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:84:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
84 | for(i=1;i<=m;i++)scanf("%lld %lld",&radius,&e),op.push_back({2*radius,e,i});
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
park.cpp: In function 'int dis(int, int)':
park.cpp:37:13: warning: 'd' may be used uninitialized in this function [-Wmaybe-uninitialized]
37 | return d-r[i]-r[j];
| ~^~~~~
park.cpp: In function 'int main()':
park.cpp:37:13: warning: 'd' may be used uninitialized in this function [-Wmaybe-uninitialized]
37 | return d-r[i]-r[j];
| ~^~~~~
park.cpp:30:59: note: 'd' was declared here
30 | long long a=x[i]-x[j],b=y[i]-y[j],c=a*a+b*b,ll,rr,mid,d;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
624 ms |
66276 KB |
Output is correct |
2 |
Correct |
650 ms |
66148 KB |
Output is correct |
3 |
Correct |
621 ms |
66148 KB |
Output is correct |
4 |
Correct |
611 ms |
66112 KB |
Output is correct |
5 |
Correct |
607 ms |
66048 KB |
Output is correct |
6 |
Correct |
614 ms |
66196 KB |
Output is correct |
7 |
Correct |
599 ms |
66080 KB |
Output is correct |
8 |
Correct |
577 ms |
66032 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
4804 KB |
Output is correct |
2 |
Correct |
53 ms |
4812 KB |
Output is correct |
3 |
Correct |
47 ms |
4804 KB |
Output is correct |
4 |
Correct |
43 ms |
4804 KB |
Output is correct |
5 |
Correct |
50 ms |
4804 KB |
Output is correct |
6 |
Correct |
45 ms |
4836 KB |
Output is correct |
7 |
Correct |
38 ms |
3528 KB |
Output is correct |
8 |
Correct |
40 ms |
4608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
624 ms |
66276 KB |
Output is correct |
2 |
Correct |
650 ms |
66148 KB |
Output is correct |
3 |
Correct |
621 ms |
66148 KB |
Output is correct |
4 |
Correct |
611 ms |
66112 KB |
Output is correct |
5 |
Correct |
607 ms |
66048 KB |
Output is correct |
6 |
Correct |
614 ms |
66196 KB |
Output is correct |
7 |
Correct |
599 ms |
66080 KB |
Output is correct |
8 |
Correct |
577 ms |
66032 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
48 ms |
4804 KB |
Output is correct |
12 |
Correct |
53 ms |
4812 KB |
Output is correct |
13 |
Correct |
47 ms |
4804 KB |
Output is correct |
14 |
Correct |
43 ms |
4804 KB |
Output is correct |
15 |
Correct |
50 ms |
4804 KB |
Output is correct |
16 |
Correct |
45 ms |
4836 KB |
Output is correct |
17 |
Correct |
38 ms |
3528 KB |
Output is correct |
18 |
Correct |
40 ms |
4608 KB |
Output is correct |
19 |
Correct |
653 ms |
70360 KB |
Output is correct |
20 |
Correct |
658 ms |
70348 KB |
Output is correct |
21 |
Correct |
644 ms |
70364 KB |
Output is correct |
22 |
Correct |
641 ms |
70232 KB |
Output is correct |
23 |
Correct |
655 ms |
70332 KB |
Output is correct |
24 |
Correct |
641 ms |
70352 KB |
Output is correct |