Codeforces Round 685 (Div. 2)
E1
Bitwise Queries (Easy Version)
Codeforces
2000
原题
← DE2 →
翻译中…

The only difference between the easy and hard versions is the constraints on the number of queries.

翻译中…

This is an interactive problem.

翻译中…

Ridbit has a hidden array $a$ of $n$ integers which he wants Ashish to guess. Note that $n$ is a power of two. Ashish is allowed to ask three different types of queries. They are of the form

翻译中…
  • AND $i$ $j$: ask for the bitwise AND of elements $a_i$ and $a_j$ $(1 \leq i, j \le n$, $i \neq j)$
  • OR $i$ $j$: ask for the bitwise OR of elements $a_i$ and $a_j$ $(1 \leq i, j \le n$, $i \neq j)$
  • XOR $i$ $j$: ask for the bitwise XOR of elements $a_i$ and $a_j$ $(1 \leq i, j \le n$, $i \neq j)$
翻译中…

Can you help Ashish guess the elements of the array?

翻译中…

In this version, each element takes a value in the range $[0, n-1]$ (inclusive) and Ashish can ask no more than $n+2$ queries.

翻译中…

Input

翻译中…

The first line of input contains one integer $n$ $(4 \le n \le 2^{16})$ — the length of the array. It is guaranteed that $n$ is a power of two.

翻译中…

Interaction

翻译中…

To ask a query print a single line containing one of the following (without quotes)

翻译中…
  • "AND i j"
  • "OR i j"
  • "XOR i j"
翻译中…

where $i$ and $j$ $(1 \leq i, j \le n$, $i \neq j)$ denote the indices being queried.

翻译中…

For each query, you will receive an integer $x$ whose value depends on the type of query. If the indices queried are invalid or you exceed the number of queries however, you will get $x = -1$. In this case, you should terminate the program immediately.

翻译中…

When you have guessed the elements of the array, print a single line "! " (without quotes), followed by $n$ space-separated integers  — the elements of the array.

翻译中…

Guessing the array does not count towards the number of queries asked.

翻译中…

The interactor is not adaptive. The array $a$ does not change with queries.

翻译中…

After printing a query do not forget to output the end of the line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

翻译中…
  • fflush(stdout) or cout.flush() in C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
  • see the documentation for other languages.
翻译中…

Hacks

翻译中…

To hack the solution, use the following test format:

翻译中…

On the first line print a single integer $n$ $(4 \le n \le 2^{16})$ — the length of the array. It must be a power of 2. The next line should contain $n$ space-separated integers in the range $[0, n-1]$ — the array $a$.

翻译中…

Note

翻译中…

The array $a$ in the example is $[0, 0, 2, 3]$.

翻译中…

样例

Input #1
4

0

2

3
Output #1
OR 1 2

OR 2 3

XOR 2 4

! 0 0 2 3
InputCopy OutputCopy
题目信息
题号
1451E1
时间限制
4 s
内存限制
256 MB
标签
位运算
构造
交互题
数学

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