New Year and Rectangle
Time limit3sMemory limit1024 MB
Locate a hidden axis-aligned rectangle on an n by n grid using at most q count queries over an interactive judge. Standard binary search on edges with a count oracle.
- Level
Hard8 of 10
- Topics
- Binary search, Implementation, Brute force
- Solved
- No attempts yet
Statement
This is an interactive problem.
For New Year, Grandfather Frost gave Gleb the gift he had wanted for a long time: a grid square of size . The gift has a surprise. Grandfather Frost picked a non-empty rectangle inside the square and placed one tangerine in each cell of that rectangle.
To get the gift, Gleb must play a game with Grandfather Frost. Gleb has to find which rectangle contains all the tangerines. Rows and columns are numbered from to , bottom to top and left to right. Gleb can make two kinds of queries:
? x_1 y_1 x_2 y_2(, ): Grandfather Frost replies with the number of tangerines in the rectangle whose bottom-left cell is and top-right cell is .! x_1 y_1 x_2 y_2(, ): when Gleb is sure of the location, he makes this query to report his answer. is the bottom-left cell of the guessed rectangle and is its top-right cell.
Input
The program receives one integer (), the size of the square.
After each ? query, the program receives the number of tangerines in the rectangle you asked about.
Output
Print only valid queries in the format above. The last line must be a single ! query, after which the program must exit immediately. The program may print at most ? queries ( depends on the group number). The final ! query is not counted among the queries.
Follow the output format exactly. Flush the output buffer after each line: use flush(output) in Pascal or Delphi, fflush(stdout) or cout.flush() in C/C++, sys.stdout.flush() in Python, and System.out.flush() in Java.
Hint
You do not have to make the same queries as the ones in the first test to pass it.