CF2159A.MAD Interactive Problem

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is an interactive problem.

There is a secret sequence a1,a2,…,a2n−1,a2na_1, a_2, \ldots, a_{2n-1},a_{2n}, which contains each integer from 11 to nn exactly twice.

Your task is to guess the sequence by using queries of the following type:

  • "? k  j1  j2  …  jkk\;j_1\;j_2\;\ldots\;j_k" — select the integer kk (1≤k≤2n1 \le k \le 2n) and kk distinct indices j1,j2,…,jkj_1, j_2, \ldots, j_k (1≤j1,j2,…,jk≤2n1 \le j_1 , j_2 , \ldots , j_k \le 2n). In response to the query, the jury will return MAD([aj1,aj2,…,ajk])\text{MAD}([a_{j_1}, a_{j_2}, \ldots, a_{j_k}]).

We define the MAD⁡\operatorname{MAD} (Maximum Appearing Duplicate) of an integer sequence as the largest integer that appears at least twice. Specifically, if there is no number that appears at least twice, the MAD⁡\operatorname{MAD} value is 00. Some examples are as follows:

  • MAD⁡([1,2,1])=1\operatorname{MAD}([1, 2, 1]) = 1;
  • MAD⁡([2,2,3,3])=3\operatorname{MAD}([2, 2, 3, 3]) = 3;
  • MAD⁡([1,2,3,4])=0\operatorname{MAD}([1, 2, 3, 4]) = 0.

Please identify the secret sequence using at most 3n3n queries.

这是一个交互式问题。

存在一个秘密序列 a1,a2,…,a2n−1,a2na_1, a_2, \ldots, a_{2n-1},a_{2n},其中每个从 11 到 nn 的整数恰好出现两次。

你的任务是通过以下类型的查询来推断该序列:

  • “? k  j1  j2  …  jkk\;j_1\;j_2\;\ldots\;j_k” —— 选择一个整数 kk(1≤k≤2n1 \le k \le 2n)以及 kk 个互不相同的下标 j1,j2,…,jkj_1, j_2, \ldots, j_k(1≤j1,j2,…,jk≤2n1 \le j_1 , j_2 , \ldots , j_k \le 2n)。对于该查询,评测系统将返回 MAD([aj1,aj2,…,ajk])\text{MAD}([a_{j_1}, a_{j_2}, \ldots, a_{j_k}])。

我们定义一个整数序列的 MAD⁡\operatorname{MAD}(最大重复出现值)为至少出现两次的最大整数。特别地,若序列中没有任何数出现至少两次,则 MAD⁡\operatorname{MAD} 的值为 00。例如:

  • MAD⁡([1,2,1])=1\operatorname{MAD}([1, 2, 1]) = 1;
  • MAD⁡([2,2,3,3])=3\operatorname{MAD}([2, 2, 3, 3]) = 3;
  • MAD⁡([1,2,3,4])=0\operatorname{MAD}([1, 2, 3, 4]) = 0。

请在至多 3n3n 次查询内确定该秘密序列。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤30001 \le t \le 3000). The description of the test cases follows.

The first line of each test case contains one integer nn (2≤n≤3002 \le n \le 300).

It is guaranteed that the sum of n2n^2 over all test cases does not exceed 10510^5.

After you read this line of input, the interaction begins with your first query.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤30001 \le t \le 3000)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤3002 \le n \le 300)。

保证所有测试用例的 n2n^2 之和不超过 10510^5。

在读入该输入行后,交互即从你的第一个查询开始。

输入输出样例

  • 输入#1

    2
    2
    
    2
    
    0
    
    1
    
    2
    
    0
    
    1
    
    1

    输出#1

    ? 2 2 1
    
    ? 2 1 3
    
    ? 3 1 3 4
    
    ! 2 2 1 1
    
    ? 2 1 2
    
    ? 2 1 3
    
    ? 3 1 3 4
    
    ! 1 2 1 2

说明/提示

In the first test case, the hidden sequence is a=[2,2,1,1]a=[2,2,1,1].

For the query "? 2 2 1", the jury returns 22 because MAD⁡([a2,a1])=MAD⁡([2,2])=2\operatorname{MAD}([a_2, a_1]) = \operatorname{MAD}([2, 2]) = 2.

For the query "? 2 1 3", the jury returns 00 because MAD⁡([a1,a3])=MAD⁡([2,1])=0\operatorname{MAD}([a_1, a_3]) = \operatorname{MAD}([2, 1]) = 0.

For the query "? 3 1 3 4", the jury returns 11 because MAD⁡([a1,a3,a4])=MAD⁡([2,1,1])=1\operatorname{MAD}([a_1, a_3, a_4]) = \operatorname{MAD}([2 ,1, 1]) = 1.

Note that the example interaction is only for understanding statements and does not guarantee finding a unique sequence aa.

在第一个测试用例中,隐藏序列为 a=[2,2,1,1]a=[2,2,1,1]。

对于查询 "? 2 2 1",评测系统返回 22,因为 MAD⁡([a2,a1])=MAD⁡([2,2])=2\operatorname{MAD}([a_2, a_1]) = \operatorname{MAD}([2, 2]) = 2。

对于查询 "? 2 1 3",评测系统返回 00,因为 MAD⁡([a1,a3])=MAD⁡([2,1])=0\operatorname{MAD}([a_1, a_3]) = \operatorname{MAD}([2, 1]) = 0。

对于查询 "? 3 1 3 4",评测系统返回 11,因为 MAD⁡([a1,a3,a4])=MAD⁡([2,1,1])=1\operatorname{MAD}([a_1, a_3, a_4]) = \operatorname{MAD}([2 ,1, 1]) = 1。

注意:该示例交互仅用于帮助理解题意,并不能保证唯一确定序列 aa。

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

首页