E. Serval and Snake
binary search; brute force; interactive
This is an interactive problem.Now Serval is a senior high school student in Japari Middle School. However, on the way to the school, he must go across a pond, in which there is a dangerous snake. The pond can be represented as a \(n \times n\) grid. The snake has a head and a tail in different cells, and its body is a series of adjacent cells connecting the head and the tail without self-intersecting. If Serval hits its head or tail, the snake will bite him and he will die.Luckily, he has a special device which can answer the following question: you can pick a rectangle, it will tell you the number of times one needs to cross the border of the rectangle walking cell by cell along the snake from the head to the tail. The pictures below show a possible snake and a possible query to it, which will get an answer of \(4\). Today Serval got up too late and only have time to make \(2019\) queries. As his best friend, can you help him find the positions of the head and the tail?Note that two cells are adjacent if and only if they have a common edge in the grid, and a snake can have a body of length \(0\), that means it only has adjacent head and tail.Also note that the snake is sleeping, so it won't move while Serval using his device. And what's obvious is that the snake position does not depend on your queries.
The first line contains a single integer \(n\) (\(2\leq n \leq 1000\)) — the size of the grid.
When you are ready to answer, you should print ! x1 y1 x2 y2, where \((x_1, y_1)\) represents the position of the head and \((x_2,y_2)\) represents the position of the tail. You can print head and tail in any order.
The pictures above show our queries and the answers in the first example. We first made a query for \((1,1)\) and got an answer \(1\), then found that it must be connected to exactly one other cell. Then we made a query for \((1,2)\) and got an answer of \(0\), then knew that the snake never entered it. So the cell connected to \((1,1)\) must be \((2,1)\). Then we made a query for \((2,2)\) and got an answer \(0\), then knew that it never entered \((2,2)\) as well. So the snake cannot leave \((2,1)\), which implies that the answer is \((1,1)\) and \((2,1)\). The pictures above show our queries and the answers in the second example. By making query to \((2,2)\) and receiving \(2\), we found that the snake occupies \((2,2)\). And by making query to rectangle from \((2,1)\) to \((2,3)\) and receiving answer \(0\), we knew that it never goes out of the rectangle from \((2,1)\) to \((2,3)\). Since the first answer is \(2\), both \((2,1)\) and \((2,3)\) must be occupied but none of others, so the answer is \((2,1)\) and \((2,3)\).