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,a2n, which contains each integer from 1 to n exactly twice.
Your task is to guess the sequence by using queries of the following type:
- "? kj1j2…jk" — select the integer k (1≤k≤2n) and k distinct indices j1,j2,…,jk (1≤j1,j2,…,jk≤2n). In response to the query, the jury will return MAD([aj1,aj2,…,ajk]).
We define the 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 value is 0. Some examples are as follows:
- MAD([1,2,1])=1;
- MAD([2,2,3,3])=3;
- MAD([1,2,3,4])=0.
Please identify the secret sequence using at most 3n queries.
这是一个交互式问题。
存在一个秘密序列 a1,a2,…,a2n−1,a2n,其中每个从 1 到 n 的整数恰好出现两次。
你的任务是通过以下类型的查询来推断该序列:
- “? kj1j2…jk” —— 选择一个整数 k(1≤k≤2n)以及 k 个互不相同的下标 j1,j2,…,jk(1≤j1,j2,…,jk≤2n)。对于该查询,评测系统将返回 MAD([aj1,aj2,…,ajk])。
我们定义一个整数序列的 MAD(最大重复出现值)为至少出现两次的最大整数。特别地,若序列中没有任何数出现至少两次,则 MAD 的值为 0。例如:
- MAD([1,2,1])=1;
- MAD([2,2,3,3])=3;
- MAD([1,2,3,4])=0。
请在至多 3n 次查询内确定该秘密序列。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤3000). The description of the test cases follows.
The first line of each test case contains one integer n (2≤n≤300).
It is guaranteed that the sum of n2 over all test cases does not exceed 105.
After you read this line of input, the interaction begins with your first query.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤3000)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(2≤n≤300)。
保证所有测试用例的 n2 之和不超过 105。
在读入该输入行后,交互即从你的第一个查询开始。
输入输出样例
输入#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].
For the query "? 2 2 1", the jury returns 2 because MAD([a2,a1])=MAD([2,2])=2.
For the query "? 2 1 3", the jury returns 0 because MAD([a1,a3])=MAD([2,1])=0.
For the query "? 3 1 3 4", the jury returns 1 because MAD([a1,a3,a4])=MAD([2,1,1])=1.
Note that the example interaction is only for understanding statements and does not guarantee finding a unique sequence a.
在第一个测试用例中,隐藏序列为 a=[2,2,1,1]。
对于查询 "? 2 2 1",评测系统返回 2,因为 MAD([a2,a1])=MAD([2,2])=2。
对于查询 "? 2 1 3",评测系统返回 0,因为 MAD([a1,a3])=MAD([2,1])=0。
对于查询 "? 3 1 3 4",评测系统返回 1,因为 MAD([a1,a3,a4])=MAD([2,1,1])=1。
注意:该示例交互仅用于帮助理解题意,并不能保证唯一确定序列 a。
输入解题思路,AI测评打分。不知道怎么写?