103554: [Atcoder]ABC355 E - Guess the Sum
Description
Score : $500$ points
Problem Statement
This is an interactive problem (where your program interacts with the judge via input and output).
You are given a positive integer $N$ and integers $L$ and $R$ such that $0 \leq L \leq R < 2^N$. The judge has a hidden sequence $A = (A_0, A_1, \dots, A_{2^N-1})$ consisting of integers between $0$ and $99$, inclusive.
Your goal is to find the remainder when $A_L + A_{L+1} + \dots + A_R$ is divided by $100$. However, you cannot directly know the values of the elements in the sequence $A$. Instead, you can ask the judge the following question:
- Choose non-negative integers $i$ and $j$ such that $2^i(j+1) \leq 2^N$. Let $l = 2^i j$ and $r = 2^i (j+1) - 1$. Ask for the remainder when $A_l + A_{l+1} + \dots + A_r$ is divided by $100$.
Let $m$ be the minimum number of questions required to determine the remainder when $A_L + A_{L+1} + \dots + A_R$ is divided by $100$ for any sequence $A$. You need to find this remainder within $m$ questions.
Constraints
- $1 \leq N \leq 18$
- $0 \leq L \leq R \leq 2^N - 1$
- All input values are integers.
Input and Output
This is an interactive problem (where your program interacts with the judge via input and output).
First, read the integers $N$, $L$, and $R$ from Standard Input:
$N$ $L$ $R$
Then, repeat asking questions until you can determine the remainder when $A_L + A_{L+1} + \dots + A_R$ is divided by $100$. Each question should be printed in the following format:
$?$ $i$ $j$
Here, $i$ and $j$ must satisfy the following constraints:
- $i$ and $j$ are non-negative integers.
- $2^i(j+1) \leq 2^N$
The response to the question will be given in the following format from Standard Input:
$T$
Here, $T$ is the answer to the question, which is the remainder when $A_l + A_{l+1} + \dots + A_r$ is divided by $100$, where $l = 2^i j$ and $r = 2^i (j+1) - 1$.
If $i$ and $j$ do not satisfy the constraints, or if the number of questions exceeds $m$, then $T$ will be -1
.
If the judge returns -1
, your program is already considered incorrect. In this case, terminate the program immediately.
Once you have determined the remainder when $A_L + A_{L+1} + \dots + A_R$ is divided by $100$, print the remainder $S$ in the following format and terminate the program immediately:
$!$ $S$
Notes
- At the end of each output, print a newline and flush Standard Output. Otherwise, the verdict may be TLE.
- If your output is malformed or your program exits prematurely, the verdict will be indeterminate.
- After printing the answer, terminate the program immediately. Otherwise, the verdict will be indeterminate.
Example
Here is an example for $N=3$, $L=1$, $R=5$, and $A=(31, 41, 59, 26, 53, 58, 97, 93)$. In this case, $m=3$, so you can ask up to three questions.
Input | Output |
Desc |
---|---|---|
3 1 5
|
|
First, the integers $N$, $L$, and $R$ are given. |
|
? 0 1
|
Ask the question with $(i, j) = (0, 1)$. |
41
|
|
$l=1$ and $r=1$, so the response is the remainder when $A_1=41$ is divided by $100$, which is $41$. The judge returns this value. |
|
? 1 1
|
Ask the question with $(i, j) = (1, 1)$. |
85
|
|
$l=2$ and $r=3$, so the response is the remainder when $A_2 + A_3 = 85$ is divided by $100$, which is $85$. The judge returns this value. |
|
? 1 2
|
Ask the question with $(i, j) = (1, 2)$. |
11
|
|
$l=4$ and $r=5$, so the response is the remainder when $A_4 + A_5 = 111$ is divided by $100$, which is $11$. The judge returns this value. |
|
! 37
|
The answer is $37$, so print this value. |
Output
问题描述
这是一个交互式问题(你的程序需要通过输入和输出与裁判交互)。
你将得到一个正整数$N$以及整数$L$和$R$,满足$0 \leq L \leq R < 2^N$。裁判有一个隐藏的序列$A = (A_0, A_1, \dots, A_{2^N-1})$,其中包含0到99(包括0和99)之间的整数。
你的目标是找到$A_L + A_{L+1} + \dots + A_R$除以100的余数。然而,你不能直接得知序列$A$中元素的值。相反,你可以向裁判提出以下问题:
- 选择非负整数$i$和$j$,满足$2^i(j+1) \leq 2^N$。令$l = 2^i j$和$r = 2^i (j+1) - 1$。询问$A_l + A_{l+1} + \dots + A_r$除以100的余数。
设$m$为找到任何序列$A$中$A_L + A_{L+1} + \dots + A_R$除以100的余数所需的最小问题数量。你需要在$m$个问题内找到这个余数。
限制条件
- $1 \leq N \leq 18$
- $0 \leq L \leq R \leq 2^N - 1$
- 所有输入值都是整数。
输入与输出
这是一个交互式问题(你的程序需要通过输入和输出与裁判交互)。
首先,从标准输入读取整数$N$、$L$和$R$:
$N$ $L$ $R$
然后,重复提问,直到你能确定$A_L + A_{L+1} + \dots + A_R$除以100的余数。每个问题应以以下格式打印:
$?$ $i$ $j$
其中,$i$和$j$必须满足以下条件:
- $i$和$j$是非负整数。
- $2^i(j+1) \leq 2^N$
问题的回答将以以下格式从标准输入给出:
$T$
其中,$T$是问题的答案,即$A_l + A_{l+1} + \dots + A_r$除以100的余数,其中$l = 2^i j$,$r = 2^i (j+1) - 1$。
如果$i$和$j$不满足条件,或者问题数量超过$m$,则$T$将为-1
。
如果裁判返回-1
,你的程序被认为不正确。在这种情况下,立即终止程序。
一旦你确定了$A_L + A_{L+1} + \dots + A_R$除以100的余数,以以下格式打印余数$S$并立即终止程序:
$!$ $S$
注意
- 在每个输出的末尾打印一个换行符并刷新标准输出。否则,判决可能为TLE(超时)。
Sample Input Copy
Sample Output Copy