codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1520F1.md (3385B)


      1 Source: https://codeforces.com/problemset/problem/1520/F1
      2 
      3 F1. Guess the K-th Zero (Easy version)
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 This is an interactive problem.
     22 
     23 This is an easy version of the problem. The difference from the hard version is that in the easy version $t=1$ and the number of queries is limited to $20$.
     24 
     25 Polycarp is playing a computer game. In this game, an array consisting of zeros and ones is hidden. Polycarp wins if he guesses the position of the $k$-th zero from the left $t$ times.
     26 
     27 Polycarp can make no more than $20$ requests of the following type:
     28 
     29 * ? $l$ $r$ — find out the sum of all elements in positions from $l$ to $r$ ($1 \le l \le r \le n$) inclusive.
     30 
     31 In this (easy version) of the problem, this paragraph doesn't really make sense since $t=1$ always. To make the game more interesting, each guessed zero turns into one and the game continues on the changed array. More formally, if the position of the $k$-th zero was $x$, then after Polycarp guesses this position, the $x$-th element of the array will be replaced from $0$ to $1$. Of course, this feature affects something only for $t \gt 1$.
     32 
     33 Help Polycarp win the game.
     34 
     35 Interaction
     36 
     37 First, your program must read two integers $n$ and $t$ ($1 \le n \le 2 \cdot 10^5$, $t=1$).
     38 
     39 Then $t$ lines follow, each of which contains one integer $k$ ($1 \le k \le n$). It is guaranteed that at the moment of the request the array contains at least $k$ zeros. In order to get the next value of $k$, you must output the answer for the current value of $k$.
     40 
     41 After that, you can make no more than $20$ requests.
     42 
     43 Use the following format to output the answer (it is not a request, it doesn't count in $20$):
     44 
     45 * ! $x$ — position of the $k$-th zero.
     46 
     47 Positions in the array are numbered from left to right from $1$ to $n$ inclusive.
     48 
     49 After printing $t$ answers, your program should exit immediately.
     50 
     51 In this task, the interactor is not adaptive. This means that within the same test, the hidden array and the queries do not change.
     52 
     53 In case of an incorrect query, -1 will be displayed. When this value is received, your program must immediately exit normally (for example, by calling exit(0)), otherwise, the testing system may issue an arbitrary verdict.
     54 
     55 If the number of requests is exceeded, the verdict wrong answer will be displayed.
     56 
     57 Your solution may get the verdict Idleness limit exceeded if you don't print anything or forget to flush the output buffer.
     58 
     59 To flush the output buffer, you need to do the following immediately after the query output and the end-of-line character:
     60 
     61 * fflush(stdout) or cout.flush() in C ++;
     62 * System.out.flush() in Java;
     63 * flush(output) in Pascal;
     64 * stdout.flush() in Python;
     65 * see the documentation for other languages.
     66 
     67 Hacks
     68 
     69 Use the following format for hacks:
     70 
     71 On the first line print the string $s$ ($1 \le |s| \le 2 \cdot 10^5$), consisting of zeros and ones, and an integer $t$ ($t = 1$) — hidden array and number of requests, respectively. In the next $t$ lines output the number $k$ ($1 \le k \le |s|$).
     72 
     73 The hacked solution will not have direct access to the hidden array.
     74 
     75 Example
     76 
     77 Input
     78 
     79 ```
     80 6 1
     81 2
     82 
     83 2
     84 
     85 1
     86 
     87 1
     88 
     89 0
     90 
     91 0
     92 ```
     93 
     94 Output
     95 
     96 ```
     97 ? 4 6
     98 
     99 ? 1 1
    100 
    101 ? 1 2
    102 
    103 ? 2 2
    104 
    105 ? 5 5
    106 
    107 ! 5
    108 ```
    109 
    110 Note
    111 
    112 In the first test, the $[1, 0, 1, 1, 0, 1]$ array is hidden. In this test $k=2$.