Problems > Inside, Outside, or On the Fence

Inside, Outside, or On the Fence

Difficulty: 1900 6000 ms 128 MB

geometry

Given a simple polygon and Q query points, classify each point as INSIDE, OUTSIDE, or BORDER.

Input: the first line has N; the next N lines are the polygon vertices in order; then a line with Q; then Q query points x y.

Output: one line per query.

Constraints:

  • 3 ≤ N ≤ 103
  • 1 ≤ Q ≤ 103
  • |coordinates| ≤ 106

Sample Tests

Input 1
4
0 0
4 0
4 4
0 4
3
2 2
5 5
0 2
Output 1
INSIDE
OUTSIDE
BORDER
Input 2
3
0 0
2 0
0 2
1
1 1
Output 2
BORDER

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.