CF1556D.Take a Guess

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

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 2⋅n2 \cdot n of the following questions:

  • What is the result of a bitwise AND of two items with indices ii and jj (i≠ji \neq j)
  • What is the result of a bitwise OR of two items with indices ii and jj (i≠ji \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] 44th smallest number is equal to 55, and 22nd and 33rd are 33.

这是一个交互式题目。

威廉心中有一个整数序列 a1,a2,…,ana_1, a_2, \dots, a_n,但由于安全考虑,他并不想将该序列完全透露给你。威廉最多会回答 2⋅n2 \cdot n 个如下形式的问题:

  • 下标为 ii 和 jj(其中 i≠ji \neq j)的两个元素的按位与结果是多少?
  • 下标为 ii 和 jj(其中 i≠ji \neq j)的两个元素的按位或结果是多少?

你可以向威廉提出上述问题,你需要据此找出该序列中第 kk 小的数。

形式化地,第 kk 小的数定义为:将序列按非递减顺序排序后(下标从 1 开始),位于第 kk 个位置上的数。例如,在数组 [5,3,3,10,1][5, 3, 3, 10, 1] 中,第 44 小的数是 55,而第 22 小和第 33 小的数均为 33。

输入格式

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

保证序列中每个元素均满足条件 0≤ai≤1090 \le a_i \le 10^9。

输入输出样例

  • 输入#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.

在该示例中,隐藏序列为 [1,6,4,2,3,5,4][1, 6, 4, 2, 3, 5, 4]。

以下是该示例中的交互过程。

查询(选手程序)

响应(交互器)

说明

and 2 5

2

a2=6a_2=6,a5=3a_5=3。交互器返回所给两数的按位与(bitwise AND)结果。

or 5 6

7

a5=3a_5=3,a6=5a_6=5。交互器返回所给两数的按位或(bitwise OR)结果。

finish 5

55 是正确答案。注意:你必须找出第 kk 小的数的值,而非其下标。

输入解题思路,AI测评打分。不知道怎么写?

首页