H. Missing Number

Codeforces
IDCF10221H
Time2000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Thomas has an array of integers $a_1, med \\dots, med a_n$, and all the elements in this array are distinct and belong to the interval from $0$ to $n$. As you can see, one of the numbers from $0$ to $n$ is missing in this array. You have to find this number. You can ask the $b$-th bit of the number $a_i$ no more than $2 dot.op n + 19$ times. This is an interactive problem. Your program should communicate with the jury's program, using standard input and output for that. In the beginning your program gets a single integer $n$ ($1 <= n <= 1000$) — the size of the array. After that you can ask no more than $2 dot.op n + 19$ questions. To ask a question, output a character «_?_», and then after a space two integers $i$ and $b$ ($1 <= i <= n, 0 <= b <= log_2 n$) — the index $i$ in the array and the bit you want to know. Bits are numbered from zero, starting from the lowest. As a response you will get an integer $0$ or $1$ — the value of the $b$-th bit of the number $a_i$. When you determine the number missing in the array, output a character «_!_», and then after a space output this number. Then your program must terminate. Please note that each your message must end with a line break. Also after outputting each message your program must flush the stream buffer, so that the outputted information could reach jury's program: for instance, this can be done by calling «_fflush(stdout)_» or «_cout.flush()_» in C++, «_System.out.flush()_» in Java, «_Console.Out.Flush()_» in C#, «_flush(output)_» in Pascal, «_sys.stdout.flush()_» in Python. Emply lines in the sample are given only for convenience, to make it clear in which order the messages are written. When solving the problem you must not output empty lines and jury's program won't output empty lines too. ## Interaction This is an interactive problem. Your program should communicate with the jury's program, using standard input and output for that.In the beginning your program gets a single integer $n$ ($1 <= n <= 1000$) — the size of the array.After that you can ask no more than $2 dot.op n + 19$ questions. To ask a question, output a character «_?_», and then after a space two integers $i$ and $b$ ($1 <= i <= n, 0 <= b <= log_2 n$) — the index $i$ in the array and the bit you want to know. Bits are numbered from zero, starting from the lowest.As a response you will get an integer $0$ or $1$ — the value of the $b$-th bit of the number $a_i$.When you determine the number missing in the array, output a character «_!_», and then after a space output this number. Then your program must terminate. [samples] ## Note Please note that each your message must end with a line break. Also after outputting each message your program must flush the stream buffer, so that the outputted information could reach jury's program: for instance, this can be done by calling «_fflush(stdout)_» or «_cout.flush()_» in C++, «_System.out.flush()_» in Java, «_Console.Out.Flush()_» in C#, «_flush(output)_» in Pascal, «_sys.stdout.flush()_» in Python.Emply lines in the sample are given only for convenience, to make it clear in which order the messages are written. When solving the problem you must not output empty lines and jury's program won't output empty lines too.
**Definitions** Let $ n \in \mathbb{Z}^+ $ be the number of sinusoidal waves. Let $ \omega \in \mathbb{R}^+ $ be the common angular frequency. For each $ i \in \{1, \dots, n\} $, let $ A_i \in \mathbb{R}^+ $ and $ \phi_i \in [0, 2\pi) $ be the amplitude and phase of the $ i $-th wave: $$ f_i(t) = A_i \sin(\omega t + \phi_i) $$ The combined wave is: $$ f(t) = \sum_{i=1}^n f_i(t) = \sum_{i=1}^n A_i \sin(\omega t + \phi_i) $$ We seek a single equivalent wave: $$ f(t) = A \sin(\omega t + \phi) $$ with $ A > 0 $ and $ \phi \in [0, 2\pi) $. **Constraints** 1. $ 1 \leq n \leq 10^5 $ 2. $ 0.1 \leq \omega \leq 100 $ 3. $ 0.1 \leq A_i \leq 100 $ 4. $ 0 \leq \phi_i < 2\pi $ **Objective** Compute $ A $ and $ \phi $ such that: $$ A \sin(\omega t + \phi) = \sum_{i=1}^n A_i \sin(\omega t + \phi_i) $$ Using trigonometric identity: $$ \sin(\omega t + \phi_i) = \sin(\omega t)\cos(\phi_i) + \cos(\omega t)\sin(\phi_i) $$ Define: $$ X = \sum_{i=1}^n A_i \cos(\phi_i), \quad Y = \sum_{i=1}^n A_i \sin(\phi_i) $$ Then: $$ A = \sqrt{X^2 + Y^2}, \quad \phi = \operatorname{atan2}(Y, X) $$ Output $ A $ and $ \phi $.
API Response (JSON)
{
  "problem": {
    "name": "H. Missing Number",
    "description": {
      "content": "Thomas has an array of integers $a_1, med \\\\dots, med a_n$, and all the elements in this array are distinct and belong to the interval from $0$ to $n$. As you can see, one of the numbers from $0$ to $",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10221H"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Thomas has an array of integers $a_1, med \\\\dots, med a_n$, and all the elements in this array are distinct and belong to the interval from $0$ to $n$. As you can see, one of the numbers from $0$ to $...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of sinusoidal waves.  \nLet $ \\omega \\in \\mathbb{R}^+ $ be the common angular frequency.  \nFor each $ i \\in \\{1, \\dots, n\\} $, let $ A_i \\in \\...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments