1
+ #include < bits/stdc++.h>
2
+ using namespace std ;
3
+ typedef long long ll;
4
+
5
+ struct P {
6
+ ll x, y;
7
+ void read () { cin >> x >> y; }
8
+ P operator -(P p) { return P{x - p.x , y - p.y }; }
9
+ ll cross (P p) { return x * p.y - y * p.x ; }
10
+ ll cross (P a, P b) { return (a - *this ).cross (b - *this ); }
11
+ };
12
+
13
+ void solve () {
14
+ int n, m;
15
+ cin >> n >> m;
16
+ vector<P> v (n);
17
+ for (auto &i : v) i.read ();
18
+
19
+ auto intersect = [](P cur, P p1, P p2) {
20
+ return cur.cross (p1, p2) == 0 &&
21
+ (min (p1.x , p2.x ) <= cur.x && max (p1.x , p2.x ) >= cur.x ) &&
22
+ (min (p1.y , p2.y ) <= cur.y && max (p1.y , p2.y ) >= cur.y );
23
+ };
24
+
25
+ while (m--) {
26
+ P cur;
27
+ cur.read ();
28
+
29
+ int crossings = 0 ;
30
+ bool isBoundary = false ;
31
+ for (int i = 0 ; !isBoundary && i < n; i++) {
32
+ auto p1 = v[i], p2 = v[(i + 1 ) % n];
33
+ if (p1.y > p2.y ) swap (p1, p2);
34
+
35
+ if (intersect (cur, p1, p2)) {
36
+ isBoundary = true ;
37
+ } else {
38
+ auto isTouch = cur.cross (p1, p2) >= 0 ;
39
+ auto isBetween = (p1.y < cur.y ) && (p2.y >= cur.y );
40
+ if (isTouch && isBetween) crossings++;
41
+ }
42
+ }
43
+
44
+ if (!isBoundary)
45
+ cout << (crossings & 1 ? " INSIDE\n " : " OUTSIDE\n " );
46
+ else
47
+ cout << " BOUNDARY\n " ;
48
+ }
49
+ }
50
+
51
+ int main () {
52
+ ios::sync_with_stdio (false );
53
+ cin.tie (0 );
54
+ cout.tie (0 );
55
+
56
+ int t = 1 ;
57
+ // cin >> t;
58
+ while (t--) solve ();
59
+ }
0 commit comments