| Time Limit: 1 second | |
| Memory Limit: 256 mb | |
| Interactive Problem | |
| YOU MUST USE INTERACTIVE FORMAT FOR THIS PROBLEM. | |
| You are standing in front of a row of n boxes, labeled 0 through nβ1 from left to right. | |
| Each box contains a prize that cannot be seen until the box is opened. There are v β₯ 2 | |
| different prize types, numbered from 1 to v in decreasing order of value: | |
| type 1 is the most expensive (the diamond), and type v is the cheapest (a lollipop). | |
| There is exactly one diamond in the boxes. | |
| The number of cheaper prizes is much larger than the number of more expensive ones. | |
| More precisely, for all 2 β€ t β€ v: if there are k prizes of type tβ1, then there are | |
| strictly more than k^2 prizes of type t. | |
| Your task is to find the index i of the box containing the diamond using as few | |
| queries as possible. | |
| ------------------------------------------------------------------------------- | |
| Input | |
| ------------------------------------------------------------------------------- | |
| Standard input (stdin) initially contains a single integer: | |
| n β the number of boxes. | |
| Box indices are 0-based: 0, 1, β¦, nβ1. | |
| ------------------------------------------------------------------------------- | |
| Interaction protocol (stdin/stdout) | |
| ------------------------------------------------------------------------------- | |
| Your program communicates using standard input and standard output only. | |
| There is no provided procedure to call; write a normal main program. | |
| To ask about a box i (0 β€ i < n): | |
| β’ Print a line: ? i | |
| β’ Flush the output stream immediately. | |
| Then read from stdin two integers a0 and a1 (on the same line): | |
| β’ a0 β among the boxes strictly to the left of i, the number of boxes that | |
| contain a more expensive prize than the one in box i. | |
| β’ a1 β among the boxes strictly to the right of i, the number of boxes that | |
| contain a more expensive prize than the one in box i. | |
| When you have determined the index i of the diamond (type 1), finish by: | |
| β’ Printing a line: ! i | |
| β’ Flushing the output, then terminating the program. | |
| Notes: | |
| β’ You may output extra whitespace on lines you print, but each command must be | |
| on its own line. | |
| β’ After each query line you print ("? i"), you must read exactly two integers. | |
| β’ In some test cases, the judge may be adaptive: its answers may depend on the | |
| questions you ask, but it will always remain consistent with the constraints. | |
| ------------------------------------------------------------------------------- | |
| Constraints | |
| ------------------------------------------------------------------------------- | |
| 3 β€ n β€ 200000. | |
| Each prize type is an integer between 1 and v, inclusive. | |
| There is exactly one prize of type 1 (the diamond). | |
| For all 2 β€ t β€ v, if there are k prizes of type tβ1, then there are strictly | |
| more than k^2 prizes of type t. | |
| ------------------------------------------------------------------------------- | |
| Subtasks | |
| ------------------------------------------------------------------------------- | |
| Single subtask: n β€ 200000. (All constraints above apply.) | |
| ------------------------------------------------------------------------------- | |
| Example (verbal transcript; no image) | |
| ------------------------------------------------------------------------------- | |
| Suppose n = 8 and the hidden prize types are: | |
| index: 0 1 2 3 4 5 6 7 | |
| types: 3 2 3 1 3 3 2 3 | |
| Here, index 3 holds the diamond (type 1). | |
| Possible interaction: | |
| (read) 8 | |
| (you) ? 0 β (judge replies) 0 3 | |
| Meaning: left of 0 there are 0 more-expensive prizes; right of 0 there | |
| are 3 more-expensive prizes than the prize at 0. | |
| (you) ? 2 β (judge replies) 1 2 | |
| Meaning: among indices {0,1}, exactly one is more expensive than 2βs; | |
| among {3,4,5,6,7}, exactly two are more expensive than 2βs. | |
| (you) ? 3 β (judge replies) 0 0 | |
| Meaning: no box on either side is more expensive than 3βs prize. | |
| (you) ! 3 (finish) | |
| The exact sequence of queries you make can differ; this is only an illustrative | |
| transcript of the format. | |
| ------------------------------------------------------------------------------- | |
| Scoring | |
| ------------------------------------------------------------------------------- | |
| Let q be the number of queries you print (i.e., the number of lines of the form "? i"). | |
| Your raw score for a test is: | |
| 5000 β q (clamped below at 0 if needed). | |
| Your overall score is your average raw score divided by the best score. | |
| ------------------------------------------------------------------------------- | |
| Output | |
| ------------------------------------------------------------------------------- | |
| Print exactly one final line of the form: | |
| ! i | |
| where i is the index (0 β€ i < n) of the box containing the diamond. | |
| IMPORTANT NOTE: Make sure to print out answer at the end of your code. Even if you did not find the diamond, print any arbitrary index before exiting. | |