White Sheet
Contest: Codeforces Round 587 (Div. 3)
Difficulty rating: 1700
Tags: geometry, math

There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates $$$(0, 0)$$$, and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates $$$(x_1, y_1)$$$, and the top right — $$$(x_2, y_2)$$$.

After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are $$$(x_3, y_3)$$$, and the top right — $$$(x_4, y_4)$$$. Coordinates of the bottom left corner of the second black sheet are $$$(x_5, y_5)$$$, and the top right — $$$(x_6, y_6)$$$.

Example of three rectangles.

Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets.

Input format:
The first line of the input contains four integers $$$x_1, y_1, x_2, y_2$$$ $$$(0 \le x_1 < x_2 \le 10^{6}, 0 \le y_1 < y_2 \le 10^{6})$$$ — coordinates of the bottom left and the top right corners of the white sheet.

The second line of the input contains four integers $$$x_3, y_3, x_4, y_4$$$ $$$(0 \le x_3 < x_4 \le 10^{6}, 0 \le y_3 < y_4 \le 10^{6})$$$ — coordinates of the bottom left and the top right corners of the first black sheet.

The third line of the input contains four integers $$$x_5, y_5, x_6, y_6$$$ $$$(0 \le x_5 < x_6 \le 10^{6}, 0 \le y_5 < y_6 \le 10^{6})$$$ — coordinates of the bottom left and the top right corners of the second black sheet.

The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes.

Output format:
If some part of the white sheet can be seen from the above after the two black sheets are placed, print "YES" (without quotes). Otherwise print "NO".

Constraints:
Time limit: 1.0 s
Memory limit: 256.0 MB

Note:
In the first example the white sheet is fully covered by black sheets.

In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point $$$(6.5, 4.5)$$$ lies not strictly inside the white sheet and lies strictly outside of both black sheets.

Example input:
2 2 4 4
1 1 3 5
3 1 5 5

Example output:
NO

Example input:
3 3 7 5
0 0 4 6
0 0 7 4

Example output:
YES

Editorial:
There are at least two solution to the problem. I'll describe both of them.
The first solution: firstly let's notice that the point we search can have non-integer coordinates, but if the answer exists then there will be the answer such that its point has at most half-integer coordinates. So let's multiply all coordinates by two and solve the problem with integer coordinates. The second thing is that for some $$$x$$$ there is only two points we need to check — top point with this $$$x$$$ and bottom point with this $$$x$$$. The same for some $$$y$$$. So we can iterate over all possible values of $$$x$$$ and check if the point $$$(x, y_1)$$$ lies outside of both black rectangles. The same with point $$$(x, y_2)$$$. Then do the same for points $$$(y, x_1)$$$ and $$$(y, x_2)$$$. $$$x$$$ should be in range $$$[x_1; x_2]$$$ and $$$y$$$ should be in range $$$[y_1; y_2]$$$. Time complexity is linear on size of the white rectangle.
The second solution is most tricky but has the better time complexity. Let $$$wb_1$$$ be the intersection of white rectangle and the first black rectangle, $$$wb_2$$$ the same but with the second black rectangle and $$$inter$$$ be the intersection of $$$wb_1$$$ and $$$wb_2$$$. Then it is obvious that the answer exists if $$$wb_1$$$ and $$$wb_2$$$ doesn't cover the whole white rectangle ($$$sq(w) > sq(wb_1) + sq(wb_2) - sq(inter)$$$). Time complexity: $$$O(1)$$$.