Boxlings

View as PDF

Submit solution

Points: 15 (partial)
Time limit: 1.4s
Memory limit: 256M

Author:
Problem type

Doctor Y, always eager to further his research in the field of boxology, is observing a family of boxen in their natural habitat - a barrel of wine. He has noticed that in addition to the N (1 \le N \le 200\,000) rectangular, two-dimensional boxen, there are M (1 \le M \le 200\,000) almost imperceptible points floating on the surface of the wine. He reasons that these must be baby boxen - also known as boxlings.

Curious as to the customs of box families, Doctor Y wishes to count how many boxlings are floating on top of boxen. From his top-down view of the barrel, he has divided the surface of the wine into a two-dimensional Cartesian plane, and noted the positions of all the boxen and boxlings. Each box occupies a rectangular region parallel to the axes of the plane, with its lower-left corner at (x_1, y_1) and its upper-right corner at (x_2, y_2), such that (-10^8 \le x_1 < x_2 \le 10^8) and (-10^8 \le y_1 < y_2 \le 10^8). Doctor Y has observed that boxen sometimes overlap one another. Each boxling is so small that it occupies only a single point on the plane, with x-coordinate a and y-coordinate b, such that (-10^8 \le a, b \le 10^8).

Having recorded the locations of all the life forms on the surface of the wine, Doctor Y is interested in counting exactly how many boxlings are floating on top of at least one box. Note that if a boxling is on the very edge or corner of a box, it counts as being on top. Also note that two boxlings can occupy the exact same locations, and that they should be counted separately.

With so many boxen and boxlings living in this wine barrel, Doctor Y doesn't feel like sitting there and counting them all by hand, crazy though he is. As such, he wants you to write a program to, given the locations of all the boxen and boxlings, count the number of boxlings that are floating on top of at least one box. Don't worry; your hard work will surely lead to exciting discoveries in the field of boxology.

Input Specification

Line 1: Two integers - N and M

The next N lines: Four integers - x_1, y_1, x_2 and y_2

The next M lines: Two integers - a and b

Output Specification

A single integer - the number of boxlings that are on top of at least one box.

Sample Input

5 10
-1 -1 2 5
4 -3 5 3
1 2 4 4
5 -6 8 -4
1 -2 8 0
1 4
5 4
2 2
3 1
6 -5
5 -1
3 -3
-1 -2
-1 -1
2 -1

Sample Output

6

Explanation

Below is a top-down view of the surface of the wine:

The coloured-in squares are the boxen, the red dots are boxlings that are on top of at least one box, and the blue dots are the other boxlings. Counting the red dots, it can be seen that there are six of them.


Comments

There are no comments at the moment.