1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
| #include<bits/stdc++.h>
using namespace std;
using Real = long long;
struct Point {
Real x, y;
Point() {}
Point(Real x, Real y) : x(x), y(y) {}
friend istream& operator >> (istream &is, Point& v) {
return is >> v.x >> v.y;
}
Point& operator+= (const Point& p) {
x += p.x, y += p.y;
return *this;
}
Point& operator-= (const Point& p) {
x -= p.x, y -= p.y;
return *this;
}
Point operator+ (const Point& p) const {
return Point(*this) += p;
}
Point operator- (const Point& p) const {
return Point(*this) -= p;
}
Point operator- () {
return Point(-x, -y);
}
friend Real crs(const Point& a, const Point& b) {
return a.x * b.y - a.y * b.x;
}
bool operator< (const Point& p) const {
if(x != p.x) return x < p.x;
return y < p.y;
}
};
using Points = vector<Point>;
enum position { CCW = 1, CW = -1, ON = 0 };
int ccw(const Point& a, Point b, Point c) {
b -= a, c -= a;
if(crs(b, c) > 0) return CCW;
if(crs(b, c) < 0) return CW;
return ON;
}
int ccw(Point a, Point b) {
return ccw(Point(0, 0), a, b);
}
Points Convexhell(Points& ps) {
int n = ps.size(), k = 0;
Points res(2 * n);
sort(ps.begin(), ps.end());
for(int i = 0; i < n; res[k ++] = ps[i ++]) {
while(k >= 2 && ccw(res[k - 2], res[k - 1], ps[i]) != CCW) {
k --;
}
}
for(int i = n - 2, t = k + 1; i >= 0; res[k ++] = ps[i --]) {
while(k >= t && ccw(res[k - 2], res[k - 1], ps[i]) != CCW) {
k --;
}
}
res.resize(k - 1);
return res;
}
Points Minkowski(Points& A, Points& B) {
int n = A.size(), m = B.size();
Points res (n + m + 1);
res[0] = A[0] + B[0];
int k = 1, i = 0, j = 0;
int cA = 0, cB = 0;
while(cA < n && cB < m) {
int nxi = (i + 1) % n, nxj = (j + 1) % m;
Point x = A[nxi] - A[i];
Point y = B[nxj] - B[j];
if(ccw(x, y) == CCW) {
res[k ++] = res[k - 1] + x;
i = nxi, cA ++;
} else if(ccw(x, y) == CW) {
res[k ++] = res[k - 1] + y;
j = nxj, cB ++;
} else {
res[k ++] = res[k - 1] + x + y;
j = nxj, i = nxi;
cA ++, cB ++;
}
}
while(cA < n) {
int nxi = (i + 1) % n;
res[k ++] = res[k - 1] + A[nxi] - A[i];
cA ++, i = nxi;
}
while(cB < m) {
int nxj = (j + 1) % m;
res[k ++] = res[k - 1] + B[nxj] - B[j];
cB ++, j = nxj;
}
res.resize(k - 1);
return res;
}
bool check_in(Point& p, Points& ps) {
int n = ps.size();
int O = 0, l = 1, r = n - 1;
if(ccw(ps[O], ps[r], p) == CCW || ccw(ps[O], ps[l], p) == CW) {
return false;
}
while(l + 1 < r) {
int m = l + r >> 1;
if(ccw(ps[O], ps[m], p) == CCW) {
l = m;
} else {
r = m;
}
}
if(ccw(ps[l], ps[r], p) == CW) {
return false;
} else {
return true;
}
}
void solve() {
int n, m, q;
cin >> n >> m >> q;
Points A(n), B(m);
for(int i = 0; i < n; i ++) {
cin >> A[i];
}
for(int i = 0; i < m; i ++) {
cin >> B[i];
B[i] = -B[i];
}
A = Convexhell(A); n = A.size();
B = Convexhell(B); m = B.size();
Points C = Minkowski(A, B);
while(q --) {
Point query;
cin >> query;
if(check_in(query, C)) {
cout << "1\n";
} else {
cout << "0\n";
}
}
}
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int _ = 1;
while(_ --) solve();
}
|