Problems > Points in the Box

Points in the Box

Difficulty: 1000 3500 ms 128 MB

geometry

Count the points lying inside or on the border of the axis-aligned rectangle with corners (x1, y1) and (x2, y2).

Input: the first line has N x1 y1 x2 y2 (x1 ≤ x2, y1 ≤ y2); the next N lines each have a point x y.

Output: the number of points in the closed rectangle.

Constraints:

  • 1 ≤ N ≤ 5×104
  • |coordinates| ≤ 106

Sample Tests

Input 1
3 0 0 2 2
1 1
2 2
3 0
Output 1
2
Input 2
1 0 0 0 0
0 0
Output 2
1

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.