CF1556D.Take a Guess

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

This is an interactive task

William has a certain sequence of integers a1,a2,,ana_1, a_2, \dots, a_n in his mind, but due to security concerns, he does not want to reveal it to you completely. William is ready to respond to no more than 2n2 \cdot n of the following questions:

  • What is the result of a bitwise AND of two items with indices ii and jj ( iji \neq j )
  • What is the result of a bitwise OR of two items with indices ii and jj ( iji \neq j )

You can ask William these questions and you need to find the kk -th smallest number of the sequence.

Formally the kk -th smallest number is equal to the number at the kk -th place in a 1-indexed array sorted in non-decreasing order. For example in array [5,3,3,10,1][5, 3, 3, 10, 1] 44 th smallest number is equal to 55 , and 22 nd and 33 rd are 33 .

输入格式

It is guaranteed that for each element in a sequence the condition 0ai1090 \le a_i \le 10^9 is satisfied.

输出格式

In the first line you will be given two integers nn and kk (3n104,1kn)(3 \le n \le 10^4, 1 \le k \le n) , which are the number of items in the sequence aa and the number kk .

After that, you can ask no more than 2n2 \cdot n questions (not including the "finish" operation).

Each line of your output may be of one of the following types:

  • "or i j" (1i,jn,ij)(1 \le i, j \le n, i \neq j) , where ii and jj are indices of items for which you want to calculate the bitwise OR.
  • "and i j" (1i,jn,ij)(1 \le i, j \le n, i \neq j) , where ii and jj are indices of items for which you want to calculate the bitwise AND.
  • "finish res", where resres is the kk th smallest number in the sequence. After outputting this line the program execution must conclude.

In response to the first two types of queries, you will get an integer xx , the result of the operation for the numbers you have selected.

After outputting a line do not forget to output a new line character and flush the output buffer. Otherwise you will get the "Idleness limit exceeded". To flush the buffer use:

  • fflush(stdout) in C++
  • System.out.flush() in Java
  • stdout.flush() in Python
  • flush(output) in Pascal
  • for other languages refer to documentation

If you perform an incorrect query the response will be 1-1 . After receiving response 1-1 you must immediately halt your program in order to receive an "Incorrect answer" verdict.

Hacking

To perform a hack you will need to use the following format:

The first line must contain two integers nn and kk (3n104,1kn)(3 \le n \le 10^4, 1 \le k \le n) , which are the number of items in the sequence aa and the number kk .

The second line must contain nn integers a1,a2,,ana_1, a_2, \dots, a_n (0ai109)(0 \le a_i \le 10^9) , the sequence aa .

输入输出样例

  • 输入#1

    7 6
    
    2
    
    7

    输出#1

    and 2 5
    
    or 5 6
    
    finish 5

说明/提示

In the example, the hidden sequence is [1,6,4,2,3,5,4][1, 6, 4, 2, 3, 5, 4] .

Below is the interaction in the example.

Query (contestant's program) Response (interactor) Notes and 2 5 2 a2=6a_2=6 , a5=3a_5=3 . Interactor returns bitwise AND of the given numbers. or 5 6 7 a5=3a_5=3 , a6=5a_6=5 . Interactor returns bitwise OR of the given numbers. finish 5 55 is the correct answer. Note that you must find the value and not the index of the kth smallest number.

首页