Spectral::Cup 2026 Round 1 (Codeforces Round 1094, Div. 1 + Div. 2)
E
Seek the Truth
Codeforces
2000
原题
← DF →
翻译中…

This is an interactive problem.

翻译中…

There are two hidden integers $k$ and $c$ such that $k\in \{1,2,3\}$ and $1\le c\le 2^n-1$. Note that $c\neq 0$.

翻译中…

Before any interaction, you need to tell the jury a non-negative integer $a\le 2^n-1$. The grader will then use $a$ as the initial element in the set $S$, that is, initially $S = \{a\}$.

翻译中…

Next, you can make at most $n+3$ queries of the following two types:

翻译中…
  1. Select an integer $x$ such that $0\leq x\le 2^n-1$. The jury will insert $f(x)$ into $S$ and then respond with $|S|$ (i. e., the size of $S$ after the insertion);
  2. Select an integer $y$ such that $0\leq y\le 2^n-1$. The jury will respond with the number of integers $z$ such that $z\in S$ and $z\geq y$.
翻译中…

The definition of $f(x)$ is as follows:

翻译中…

$$ f(x)= \begin{cases} x\,\&\,c & \text{if}\, k=1,\\ x\,|\,c & \text{if}\, k=2,\\ x\oplus c & \text{if}\, k=3.\\ \end{cases} $$

翻译中…

Here, $\&$ denotes the bitwise AND operation, $|$ denotes the bitwise OR operation, and $\oplus$ denotes the bitwise XOR operation.

翻译中…

Your task is to determine the values of $k$ and $c$ using at most $n+3$ interactions.

翻译中…

Please note that reporting the answer does not count towards the $n+3$ interactions.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($2 \leq n \leq 60$). Then, interaction follows.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

翻译中…

Interaction

翻译中…

First, you need to output an integer $a$ ($0\leq a\le 2^n-1$) — the initial element you chose for set $S$.

翻译中…

To make an interaction, output a single line in the following format:

翻译中…
  1. $\mathtt{I}\;x$ ($0\leq x\le 2^n-1$) — Insert $f(x)$ into set $S$. After that, the jury will return $|S|$.
  2. $\mathtt{Q}\;y$ ($0\leq y\le 2^n-1$) — Query how many $z$-s in set $S$ satisfy $z \geq y$. The jury will return the count of such $z$-s.
翻译中…

To give the final answer, output a single line in the following format:

翻译中…
  • $\mathtt{A}\;k\;c$ ($1\leq k\le 3$, $1\leq c\le 2^n-1$) — the values of $k$ and $c$.
翻译中…

After printing each query do not forget to output the end of line and flush$^{\text{∗}}$ the output. Otherwise, you will get Idleness limit exceeded verdict.

翻译中…

If, at any interaction step, you read $-1$ instead of valid data, your solution must exit immediately. This means that your solution will receive Wrong answer because of an invalid query or any other mistake. Failing to exit can result in an arbitrary verdict because your solution will continue to read from a closed stream.

翻译中…

Note that the grader is non-adaptive. This means that the values of $k$ and $c$ are fixed at the beginning and will not change based on your interactions.

翻译中…

Hacks

翻译中…

To hack, use the following format.

翻译中…

The first line should contain a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.

翻译中…

The only line of each test case should contain three integers $n$, $k$, and $c$ ($2 \leq n \leq 60$, $1\leq k\le 3$, $1\leq c\le 2^n-1$).

翻译中…

The sum of $n$ over all test cases should not exceed $10^5$.

翻译中…

$^{\text{∗}}$To flush, use: fflush(stdout) or cout.flush() in C++; sys.stdout.flush() in Python; see the documentation for other languages.

翻译中…

Note

翻译中…

Below is the interaction process in the example:

翻译中…

SolutionJuryExplanation3There are $3$ test cases.2$n=2$. The hidden integer values are $k=1$ and $c=3$.3Initially, $S = \{3\}$.I 31Insert $f(3)=3\,\& \,3=3$ into $S$. Then $S=\{3\}$, so the response is $|S|=1$. **Note that elements in set $S$ are not allowed to be repeated.**A 1 3The solution concludes that $k=1$ and $c=3$.2$n=2$. The hidden integer values are $k=2$ and $c=2$.1Initially, $S = \{1\}$.I 02Insert $f(0)=0\,|\,2=2$ into $S$. Then $S=\{1,2\}$, so the response is $|S|=2$.Q 21When $z$ is $2$, it satisfies $z\in S$ and $z\geq 2$, so the response is $1$.Q 12When $z$ is $1$ or $2$, it satisfies $z\in S$ and $z\geq 1$, so the response is $2$.Q 02When $z$ is $1$ or $2$, it satisfies $z\in S$ and $z\geq 0$, so the response is $2$.I 33Insert $f(3)=3\,|\,2=3$ into $S$. Then $S=\{1,2,3\}$, so the response is $|S|=3$.A 2 2The solution concludes that $k=2$ and $c=2$.2$n=2$. The hidden integer values are $k=3$ and $c=1$.1Initially, $S = \{1\}$.I 12Insert $f(1)=1\oplus 1=0$ into $S$. Then $S=\{0,1\}$, so the response is $|S|=2$.I 02Insert $f(1)=0\oplus 1=1$ into $S$. Then $S=\{0,1\}$, so the response is $|S|=2$. **Note that elements in set $S$ are not allowed to be repeated.**A 3 1The solution concludes that $k=3$ and $c=1$.

翻译中…

Empty lines in the example input and output are given only for better readability; you don't need to output them in your solution.

翻译中…

Note that in the example, the given queries are in fact insufficient to uniquely determine the values; they are given only to illustrate the input/output format.

翻译中…

样例

Input #1
3
2

1

2

2

1

2

2

3

2

2

2

2
Output #1
3
I 3

A 1 3

1
I 0

Q 2

Q 1

Q 0

I 3

A 2 2

1
I 1

I 0

A 3 1
InputCopy OutputCopy
题目信息
题号
2222E
时间限制
4 s
内存限制
256 MB
标签
二分
位运算
构造
交互题

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。