Fixed parities

1.8

24 votes
Problem

Alice and Bob are playing a board game. They have  boards and two arrays  and  of length . The value of each cell in the  row and  row is . Alice asks questions to Bob. In each question, Alice provides two cells and . She asks the following questions to Bob:

Are there any paths from  to  that contains the same parity as and .

Note: Bob can move from one cell to 8 neighbor cells in each step.

Input format

  • First line: An integer  denoting the length of arrays
  • Second line:  integers with  representing array
  • Third line:  integers with  representing array
  • Fourth line: An integer   denoting the number of test cases
  • For each test case:
    • First line: Two integers  denoting the row and the column of 
    • Second line: Two integers denoting the row and the column of 

Output format

For each query, if there exists a path (for example, ) from  to  that contains the same parity as and , then print YES. If the parity of A and B are different, then print NO.

Constraints

Sample Input
3
0 3 1
1 5 3
2
2 1
3 3
3 1
1 3
Sample Output
YES
NO
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the first query, we can move from to then to .

In the second query, the parity of two cells is different and therefore there isn't such a way.

Editor Image

?