Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 32768/32768 K (Java/Others)

Alice comes up with a new game and wants to play with Bob.

There is one rectangle on the paper initially, we define its lower-left corner's coordinate is (x_{L}, y_{L}) and upper-right corner's coordinate is (x_{R}, y_{R}).

Bob has executed the step as description below N times:

Bob should select one empty rectangle. If the rectangle is the initial one or is split by one vertical segment, he should split it into two parts by drawing one horizontal segment; otherwise he should split the rectangle into two parts by drawing one vertical segment. An empty rectangle means there is no segment in this rectangle except its only four boundary segments.

You should pay attention that there are only two kinds segments: vertical segment and horizontal segment.

Now Bob has several queries. In each query, Bob selects two target points in the paper. (You can assume that all given target points are always located inside the initial rectangle and not in any drawing segments.) He wants Alice to answer the question as soon as possible: Alice can erase several existing segments, and make two target points in one empty rectangle, and she should answer how many empty rectangles at most would be left at last.

But there are some restrictions: Alice cannot erase segments of the initial rectangle (the (x_{L}, y_{L}) to (x_{R}, y_{R}) one), she can only erase segments drew by Bob; if Alice want to erase one segment, both sides of the segment must be empty rectangles, and after erase it, the two empty rectangles must combine to one bigger empty rectangle; if erasing an existing segment will lead to a disconnected graph, the operation is forbidden.

There is one rectangle on the paper initially, we define its lower-left corner's coordinate is (x

Bob has executed the step as description below N times:

Bob should select one empty rectangle. If the rectangle is the initial one or is split by one vertical segment, he should split it into two parts by drawing one horizontal segment; otherwise he should split the rectangle into two parts by drawing one vertical segment. An empty rectangle means there is no segment in this rectangle except its only four boundary segments.

You should pay attention that there are only two kinds segments: vertical segment and horizontal segment.

Now Bob has several queries. In each query, Bob selects two target points in the paper. (You can assume that all given target points are always located inside the initial rectangle and not in any drawing segments.) He wants Alice to answer the question as soon as possible: Alice can erase several existing segments, and make two target points in one empty rectangle, and she should answer how many empty rectangles at most would be left at last.

But there are some restrictions: Alice cannot erase segments of the initial rectangle (the (x

There are multiple test cases.

The first line contains four integers x_{L}, y_{L}, x_{R}, y_{R} indicating the coordinates of the lower-left corner and the upper-right corner of the initial huge rectangle respectively. (-100,000 <= x_{L}, y_{L}, x_{R}, y_{R} <= 100,000, x_{L}< x_{R}, y_{L}< y_{R})

The next line contains two integers N and Q. (1 <= N, Q <= 1000)

The next N lines each line contains four integers x_{1}, y_{1}, x_{2}, y_{2} indicating the coordinates of two endpoints of one drawing segments. (-100,000 <= x_{1}, y_{1}, x_{2}, y_{2} <= 100,000, x_{1}=x_{2} | y_{1}=y_{2})

The next Q lines each line contains four integers x_{A}, y_{A}, x_{B}, y_{B} indicating the coordinates of two target points in this query. (-100,000 <= x_{A}, y_{A}, x_{B}, y_{B} <= 100,000).

The first line contains four integers x

The next line contains two integers N and Q. (1 <= N, Q <= 1000)

The next N lines each line contains four integers x

The next Q lines each line contains four integers x

提交代码