CF1451E1.Bitwise Queries (Easy Version)

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 aa of nn integers which he wants Ashish to guess. Note that nn is a power of two. Ashish is allowed to ask three different types of queries. They are of the form

  • AND ii jj : ask for the bitwise AND of elements aia_i and aja_j (1i,jn(1 \leq i, j \le n , ij)i \neq j)
  • OR ii jj : ask for the bitwise OR of elements aia_i and aja_j (1i,jn(1 \leq i, j \le n , ij)i \neq j)
  • XOR ii jj : ask for the bitwise XOR of elements aia_i and aja_j (1i,jn(1 \leq i, j \le n , ij)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,n1][0, n-1] (inclusive) and Ashish can ask no more than n+2n+2 queries.

输入格式

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

输出格式

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 ii and jj (1i,jn(1 \leq i, j \le n , ij)i \neq j) denote the indices being queried.For each query, you will receive an integer xx 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=1x = -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 nn 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 aa 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 nn (4n216)(4 \le n \le 2^{16}) — the length of the array. It must be a power of 2. The next line should contain nn space-separated integers in the range [0,n1][0, n-1] — the array aa .

输入输出样例

  • 输入#1

    4
    
    0
    
    2
    
    3

    输出#1

    OR 1 2
    
    OR 2 3
    
    XOR 2 4
    
    ! 0 0 2 3

说明/提示

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

首页