#P7345. 【DSOI 2021】吟唱的金色花海

【DSOI 2021】吟唱的金色花海

Description

At some moment, a golden tulip appears at some position. Then, starting from the next second, every second, each golden tulip will chant to all white tulips among the four adjacent points (up, down, left, right), turning them into golden tulips.

Now you are given a point (x0,y0)(x_0,y_0), and the second tt at which it has just turned into a golden tulip since the first golden tulip appeared. You need to find the position where the very first golden tulip appeared.

Each time, you may output one line 0 x y, then the program will return a value 00 or 11. 00 means that (x,y)(x,y) is a white tulip at the tt-th second, and 11 means that (x,y)(x,y) is a golden tulip at the tt-th second.
You may output one line 1 x y to tell the program that the position of the first golden tulip is (x,y)(x,y), and thus terminate the program.

Input Format

This problem has multiple test cases.
The first line contains a positive integer QQ, meaning there are QQ test cases.
For each test case, the interaction starts by reading four integers t,x0,y0,kt,x_0,y_0,k, separated by single spaces. They mean that at the tt-th second, the tulip at (x0,y0)(x_0,y_0) has just turned golden. You can ask at most kk queries.

Output Format

For each test case, after you determine the answer, output one line 1 x y to end this test case, meaning you believe (x,y)(x,y) is where the golden tulip first appeared.

Interactive Format

During the interaction, output one line in the form 0 x y to perform one operation. Then you should read a boolean value, i.e., the return value xx of this operation. If x=0x=0, it means (x,y)(x,y) is a white tulip at the tt-th second; if x=1x=1, it means (x,y)(x,y) is a golden tulip at the tt-th second.

All inputs above should be read from standard input, and all outputs should be written to standard output. After outputting one line, you must flush the buffer, otherwise you may be judged as Time Limit Exceeded. Flush the buffer as follows:

  • In C++, use fflush(stdout) or cout.flush().
  • In Pascal, use flush(output).
  • For other languages, please check the documentation yourself.
2
1 1 0 100

0

0

1

2 1 1 10000

1

1

1

1


0 1 1

0 1 -1

0 0 1

1 0 0

0 2 0

0 0 2

0 -2 0

0 0 -2

1 0 0

Hint

Test Point ID k=k = tt \le Q=Q=
1 1000010000 11 100100
2~3 55
4~6 4t4t 100100
7~10 2×MAX2 \times MAX
11~14 MAX+1MAX+1 10410^4 50005000
15~20 MAXMAX

Each test point is worth 55 points.

Note: In the worst case, asking MAX=log2(t+1)+2MAX=\lceil\log_2(t+1)\rceil+2 times is guaranteed to obtain the answer. It is guaranteed that 1t1041 \le t \le 10^4, 1Q50001 \le Q \le 5000, and the absolute values of the resulting x,yx,y are not greater than 10510^5.


Hint: Due to the nature of interactive problems, if your algorithm is wrong, it is normal for the judge result to be TLE. Please move the mouse over the test point to see the specific error reason. Specifically:

  • If your output answer is wrong, it will return You made a mistake in data i!.
  • If you ask too many queries, it will return You ask too many times in data i!.

Translated by ChatGPT 5