codeforces-scrape

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

1486C1.md (2428B)


      1 Source: https://codeforces.com/problemset/problem/1486/C1
      2 
      3 C1. Guessing the Greatest (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 The only difference between the easy and the hard version is the limit to the number of queries.
     22 
     23 This is an interactive problem.
     24 
     25 There is an array $a$ of $n$ different numbers. In one query you can ask the position of the second maximum element in a subsegment $a[l..r]$. Find the position of the maximum element in the array in no more than 40 queries.
     26 
     27 A subsegment $a[l..r]$ is all the elements $a_l, a_{l + 1}, ..., a_r$. After asking this subsegment you will be given the position of the second maximum from this subsegment in the whole array.
     28 
     29 Input
     30 
     31 The first line contains a single integer $n$ $(2 \leq n \leq 10^5)$ — the number of elements in the array.
     32 
     33 Interaction
     34 
     35 You can ask queries by printing "? $l$ $r$" $(1 \leq l \lt r \leq n)$. The answer is the index of the second maximum of all elements $a_l, a_{l + 1}, \ldots, a_r$. Array $a$ is fixed beforehand and can't be changed in time of interaction.
     36 
     37 You can output the answer by printing "! $p$", where $p$ is the index of the maximum element in the array.
     38 
     39 You can ask no more than 40 queries. Printing the answer doesn't count as a query.
     40 
     41 After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
     42 
     43 * fflush(stdout) or cout.flush() in C++;
     44 * System.out.flush() in Java;
     45 * flush(output) in Pascal;
     46 * stdout.flush() in Python;
     47 * see documentation for other languages
     48 
     49 Hacks
     50 
     51 To make a hack, use the following test format.
     52 
     53 In the first line output a single integer $n$ $(2 \leq n \leq 10^5)$. In the second line output a permutation of $n$ integers $1$ to $n$. The position of $n$ in the permutation is the position of the maximum
     54 
     55 Example
     56 
     57 Input
     58 
     59 ```
     60 5
     61 
     62 3
     63 
     64 4
     65 ```
     66 
     67 Output
     68 
     69 ```
     70 ? 1 5
     71 
     72 ? 4 5
     73 
     74 ! 1
     75 ```
     76 
     77 Note
     78 
     79 In the sample suppose $a$ is $[5, 1, 4, 2, 3]$. So after asking the $[1..5]$ subsegment $4$ is second to max value, and it's position is $3$. After asking the $[4..5]$ subsegment $2$ is second to max value and it's position in the whole array is $4$.
     80 
     81 Note that there are other arrays $a$ that would produce the same interaction, and the answer for them might be different. Example output is given in purpose of understanding the interaction.