CF1807E.Interview

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is an interactive problem. If you are unsure how interactive problems work, then it is recommended to read the guide for participants.

Before the last stage of the exam, the director conducted an interview. He gave Gon nn piles of stones, the ii-th pile having aia_i stones.

Each stone is identical and weighs 11 grams, except for one special stone that is part of an unknown pile and weighs 22 grams.

A picture of the first test case. Pile 22 has the special stone. The piles have weights of 1,3,3,4,51,3,3,4,5, respectively.

Gon can only ask the director questions of one kind: he can choose kk piles, and the director will tell him the total weight of the piles chosen. More formally, Gon can choose an integer kk (1≤k≤n1 \leq k \leq n) and kk unique piles p1,p2,…,pkp_1, p_2, \dots, p_k (1≤pi≤n1 \leq p_i \leq n), and the director will return the total weight mp1+mp2+⋯+mpkm_{p_1} + m_{p_2} + \dots + m_{p_k}, where mim_i denotes the weight of pile ii.

Gon is tasked with finding the pile that contains the special stone. However, the director is busy. Help Gon find this pile in at most 30\mathbf{30} queries.

这是一个交互式问题。如果你不确定交互式问题的工作方式,建议先阅读参赛者指南。

在考试最后一阶段之前,校长进行了一次面试。他给了 Gon nn 堆石头,其中第 ii 堆有 aia_i 颗石头。

每颗石头均相同,重量均为 11 克,但其中有一颗特殊石头例外:它属于某堆未知的石头,重量为 22 克。

第一个测试用例示意图。第 22 堆包含特殊石头。各堆重量分别为 1,3,3,4,51,3,3,4,5。

Gon 只能向校长提出一种类型的问题:他可以选择 kk 堆石头,校长会告诉他所选各堆石头的总重量。更准确地说,Gon 可以选择一个整数 kk(满足 1≤k≤n1 \leq k \leq n)以及 kk 个互不相同的堆编号 p1,p2,…,pkp_1, p_2, \dots, p_k(满足 1≤pi≤n1 \leq p_i \leq n),校长将返回总重量 mp1+mp2+⋯+mpkm_{p_1} + m_{p_2} + \dots + m_{p_k},其中 mim_i 表示第 ii 堆的总重量。

Gon 的任务是找出包含特殊石头的那一堆。然而,校长很忙。请帮助 Gon 在至多 30\mathbf{30} 次询问内找到该堆。

输入格式

The input data contains several test cases. The first line contains one integer tt (1≤t≤10001 \leq t \leq 1000) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5) — the number of piles.

The second line of each test case contains nn integers aia_i (1≤ai≤1041 \leq a_i \leq 10^4) — the number of stones in each pile.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

After reading the input for each test case, proceed with the interaction as follows.

输入数据包含多个测试用例。第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5),表示石堆的数量。

每个测试用例的第二行包含 nn 个整数 aia_i(1≤ai≤1041 \leq a_i \leq 10^4),表示每堆石子的数量。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

读取每个测试用例的输入后,按如下方式与交互系统进行交互。

输入输出样例

  • 输入#1

    2
    5
    1 2 3 4 5
    
    11
    
    6
    
    3
    
    7
    1 2 3 5 3 4 2
    
    12
    
    6

    输出#1

    ? 4 1 2 3 4
    
    ? 2 2 3
    
    ? 1 2
    
    ! 2
    
    ? 4 2 3 5 6
    
    ? 2 1 4
    
    ! 7

说明/提示

In the first test case, the stone with weight two is located in pile 22, as shown in the picture. We perform the following interaction:

  • ? 4 1 2 3 4\texttt{? 4 1 2 3 4} — ask the total weight of piles 11, 22, 33, and 44. The total weight we receive back is 1+3+3+4=111+3+3+4=11.
  • ? 2 2 3\texttt{? 2 2 3} — ask the total weight of piles 22 and 33. The total weight we receive back is 3+3=63+3=6.
  • ? 1 2\texttt{? 1 2} — ask the total weight of pile 22. The total weight we receive back is 33.
  • ! 2\texttt{! 2} — we have figured out that pile 22 contains the special stone, so we output it and move on to the next test case.

In the second test case, the stone with weight two is located on index 77. We perform the following interaction:

  • ? 4 2 3 5 6\texttt{? 4 2 3 5 6} — ask the total weight of piles 22, 33, 55, and 66. The total weight we receive back is 2+3+3+4=122+3+3+4=12.
  • ? 2 1 4\texttt{? 2 1 4} — ask the total weight of piles 11 and 44. The total weight we receive back is 1+5=61+5=6.
  • ! 7\texttt{! 7} — we have somehow figured out that pile 77 contains the special stone, so we output it and end the interaction.

在第一个测试用例中,重量为 22 的石子位于第 22 堆,如图所示。我们执行以下交互:

  • ? 4 1 2 3 4\texttt{? 4 1 2 3 4} —— 查询第 11、22、33、44 堆的总重量。返回的总重量为 1+3+3+4=111+3+3+4=11。
  • ? 2 2 3\texttt{? 2 2 3} —— 查询第 22、33 堆的总重量。返回的总重量为 3+3=63+3=6。
  • ? 1 2\texttt{? 1 2} —— 查询第 22 堆的总重量。返回的总重量为 33。
  • ! 2\texttt{! 2} —— 我们已确定第 22 堆包含特殊石子,因此输出 22 并进入下一个测试用例。

在第二个测试用例中,重量为 22 的石子位于索引 77 处。我们执行以下交互:

  • ? 4 2 3 5 6\texttt{? 4 2 3 5 6} —— 查询第 22、33、55、66 堆的总重量。返回的总重量为 2+3+3+4=122+3+3+4=12。
  • ? 2 1 4\texttt{? 2 1 4} —— 查询第 11、44 堆的总重量。返回的总重量为 1+5=61+5=6。
  • ! 7\texttt{! 7} —— 我们已确定第 77 堆包含特殊石子,因此输出 77 并结束交互。

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

首页