Trampoline

Time limit: 1.5s Memory limit: 256MB Input: Output:

Task

Little Square has started jumping on trampolines from his school’s gym. In the gym there are R×CR \times C trampolines arranged in a rectangular grid with RR rows and CC columns. Each trampoline is either green or blue. There are exactly NN green trampolines. Let (i, j)(i,\ j) denote the trampoline in the ithi^{th} row and jthj^{th} column. We index the rows from 11 to RR and the columns from 11 to CC.

Little Square’s teacher has asked him to practice T gymnastics routines. The ith routine has the following
rules:

  • The routine starts at trampoline (xistart, yistart)(x^{start}_i,\ y^{start}_i).
  • The routine ends at trampoline (xistop, yistop)(x^{stop}_i ,\ y^{stop}_i).
  • If Little Square jumps on a green trampoline at position (i, j)(i,\ j) then he may go to trampolines (i+1, j)(i + 1,\ j) or (i, j+1)(i,\ j + 1), as long as these are not outside the grid.
  • If Little Square jumps on a blue trampoline at position (i, j)(i,\ j) then he may go to trampoline (i, j+1)(i,\ j + 1), as long as it is not outside the grid.

Little Square wants to know, for each routine, if it is possible to accomplish his teacher’s request.

Input data

On the first line of the input you will find RR, CC and NN. On the next NN lines you will find the positions of the green trampolines. If a line contains integers a ba \ b then there is a green trampoline at position (a,b)(a, b). On the next line you will find TT. On the next TT lines you will find the descriptions of the gymnastics routines. On the ithi^{th} of these lines you will find xistart, yistart, xistop, yistopx^{start}_i,\ y^{start}_i,\ x^{stop}_i ,\ y^{stop}_i.

Output data

Output TT lines. The ithi^{th} line should contain Yes if it possible to accomplish the ithi^{th} routine, and No if it
is not.

Constraints and clarifications

  • 1R, C1 000 000 0001 \leq R,\ C \leq 1 \ 000 \ 000 \ 000
  • 1N, T200 0001 \leq N,\ T \leq 200 \ 000
  • 1xistart, xistopR1 \leq x^{start}_i,\ x^{stop}_i \leq R
  • 1yistart, yistopC1 \leq y^{start}_i,\ y^{stop}_i \leq C
  • The coordinates of green trampolines are pairwise distinct.
# Points Restrictions
1 23 1R, C, T2001 \leq R,\ C,\ T \leq 200
2 20 1R, C2 500,1T4 0001 \leq R,\ C \leq 2 \ 500, 1 \leq T \leq 4 \ 000
3 11 xistopxistart=1x^{stop}_i - x^{start}_i = 1
4 19 1T, N5 0001 \leq T,\ N \leq 5 \ 000
5 27 No additional constraints.

Example

stdin

4 5 2
2 2
3 4
3
2 1 4 5
1 2 1 4
2 3 4 4

stdout

Yes
Yes
No

Explanation

The trampolines are placed like so:

visual

In the first routine Little Square can go on the following route: (2, 1)(2, 2)(3, 2)(3, 3)(3, 4)(4, 4)(4, 5)(2,\ 1) \rightarrow (2,\ 2) \rightarrow (3,\ 2) \rightarrow (3,\ 3) \rightarrow (3,\ 4) \rightarrow (4,\ 4) \rightarrow (4,\ 5).

In the second routine Little Square can go on the following route: (1, 2)(1, 3)(1, 4)(1,\ 2) \rightarrow (1,\ 3) \rightarrow (1,\ 4).

The third routine cannot be accomplished.

No route exists from (2, 3)(2,\ 3) to (4, 4)(4,\ 4) that respects Little Square’s teacher’s rules.

Log in or sign up to be able to send submissions!