传送门
题意: q q q次询问把一个凸包整体加一个向量 ( x , y ) (x,y) (x,y)之后是否与另外一个凸包相交。
思路:转化一下发现只要会求 A + B = { v ⃗ = a ⃗ + b ⃗ ∣ a ⃗ ∈ A , b ⃗ ∈ B } A+B=\{\vec v=\vec a+\vec b|\vec a\in A,\vec b\in B\} A+B={v=a+b∣a∈A,b∈B}即可,这个要用到一个叫做 M i n k o w s k i Minkowski Minkowski和的东西。
不会的可以画个图,发现最后的向量集组成的凸包每条边都是由 A , B A,B A,B中的边拼成的,于是我们提出 A , B A,B A,B的所有边然后归并一下即可。
代码:
#include
#define int long long
#define ri register int
using namespace std;
inline int read(){
int ans=0;
bool f=1;
char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f^=1;ch=getchar();}
while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
return f?ans:-ans;
}
typedef long long ll;
const int N=1e5+5;
struct pot{
ll x,y;
pot(ll _x=0,ll _y=0):x(_x),y(_y){};
friend inline pot operator+(const pot&a,const pot&b){return pot(a.x+b.x,a.y+b.y);}
friend inline pot operator-(const pot&a,const pot&b){return pot(a.x-b.x,a.y-b.y);}
friend inline ll operator^(const pot&a,const pot&b){return a.x*b.y-a.y*b.x;}
friend inline bool operator<(const pot&a,const pot&b){return a.x==b.x?a.y<b.y:a.x<b.x;}
}A[N<<1],a1[N],a2[N];
inline void graham(pot a[],int&n){
static int q[N],top;
static pot b[N];
sort(a+1,a+n+1);
q[top=1]=1;
for(ri i=2;i<=n;++i){
while(top>1&&((a[i]-a[q[top-1]])^(a[q[top]]-a[q[top-1]]))<=0)--top;
q[++top]=i;
}
for(ri len=top,i=n-1;i;--i){
while(top>len&&((a[i]-a[q[top-1]])^(a[q[top]]-a[q[top-1]]))<=0)--top;
q[++top]=i;
}
n=top;
for(ri i=1;i<=n;++i)b[i]=a[q[i]];
memcpy(a,b,sizeof(b));
}
inline void Minkowski(pot a[],int&tot,pot x[],int n,pot y[],int m){
static int pa,pb;
a[tot=1]=x[pa=1]+y[pb=1];
while(pa<n&&pb<m){
pot ta=x[pa+1]-x[pa],tb=y[pb+1]-y[pb];
++tot;
if((ta^tb)<=0)a[tot]=a[tot-1]+ta,++pa;
else a[tot]=a[tot-1]+tb,++pb;
}
while(pa<n)++tot,a[tot]=a[tot-1]+x[pa+1]-x[pa],++pa;
while(pb<m)++tot,a[tot]=a[tot-1]+y[pb+1]-y[pb],++pb;
--tot;
graham(a,tot);
--tot;
}
int n,m,len,q;
inline bool check(const pot&p){
if(((p-A[1])^(A[len]-A[1]))>0)return 0;
if(((p-A[1])^(A[2]-A[1]))<0)return 0;
int l=2,r=len-1,ans=2;
while(l<=r){
int mid=l+r>>1;
if(((p-A[1])^(A[mid]-A[1]))>=0)l=mid+1,ans=mid;
else r=mid-1;
}
return ((p-A[ans])^(A[ans+1]-A[ans]))>=0;
}
signed main(){
n=read(),m=read(),q=read();
for(ri i=1;i<=n;++i)a1[i].x=read(),a1[i].y=read();
for(ri i=1;i<=m;++i)a2[i].x=-read(),a2[i].y=-read();
graham(a1,n),graham(a2,m);
Minkowski(A,len,a1,n,a2,m);
for(ri x,y;q;--q)x=read(),y=read(),cout<<check(pot(x,y))<<'\n';
return 0;
}