#P10735. Determine if Hidden Rectangle is a Square

    ID: 12769 Type: Default 1000ms 256MiB

Determine if Hidden Rectangle is a Square

Determine if Hidden Rectangle is a Square

You are given an \(N\times N\) grid that contains a hidden rectangle which occupies at least \(4\%\) of the total grid area, i.e. its area \(\geq 0.04\times N^2\). The rectangle may be either a square or a non-square rectangle. Your task is to determine whether the hidden rectangle is a square.

You need to implement the following function:

\(bool am_i_square(int\ N, int\ Q)\)

where:

  • \(N\) is the grid size, meaning the grid has \(N\) rows and \(N\) columns.
  • \(Q\) is the maximum number of queries allowed.

To determine the shape, you are allowed to call the helper function at most \(Q\) times:

\(bool inside\_shape(int\ X, int\ Y)\)

This function returns whether the cell \((X,Y)\) (with 1-based indexing) is inside the hidden rectangle.

Once you have determined the boundaries of the rectangle, return true if the rectangle is a square (i.e. its width equals its height) and false otherwise.

The judging system will call your am_i_square function for \(T\) test cases. See the Input/Output section for the details about the input format.

inputFormat

The first line of the input contains an integer \(T\) representing the number of test cases.

For each test case:

  • The first line contains two integers \(N\) and \(Q\) which represent the grid size and the maximum number of queries allowed, respectively.
  • The second line contains four integers \(X_1, Y_1, X_2, Y_2\) which denote the coordinates of the top-left cell \((X_1, Y_1)\) and the bottom-right cell \((X_2, Y_2)\) of the hidden rectangle. The rectangle occupies all cells \((x, y)\) such that \(X_1 \le x \le X_2\) and \(Y_1 \le y \le Y_2\).

Note: It is guaranteed that the area of the rectangle is at least \(4\%\) of \(N^2\) and that \(1 \le X_1 \le X_2 \le N\) and \(1 \le Y_1 \le Y_2 \le N\).

outputFormat

For each test case, output a single line with YES if the hidden rectangle is a square, and NO otherwise.

sample

3
10 100
3 3 7 7
10 100
2 2 5 8
50 200
1 10 20 29
YES

NO YES

</p>