CF2209C.Find the Zero

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is an interactive problem.

You are given an integer nn. There is a hidden array aa of length 2n2n. Each integer from 11 to nn appears exactly once in aa. The rest of the elements are all 00.

You can make the following type of query:

  • Choose two integers ii and jj (1≤i,j≤2n1 \le i,j \le 2n, i≠ji \ne j). The judge will respond with 11 if ai=aja_i=a_j, and will respond with 00 otherwise.

Find any integer kk (1≤k≤2n1 \le k \le 2n) such that ak=0a_k=0 in no more than n+1n+1 queries. Note that the interactor is adaptive, which means that the hidden array aa may change depending on your queries but will not contradict previous queries.

这是一个交互式问题。

你将得到一个整数 nn。存在一个长度为 2n2n 的隐藏数组 aa。其中,每个从 11 到 nn 的整数在 aa 中恰好出现一次,其余元素均为 00。

你可以执行如下类型的查询:

  • 选择两个整数 ii 和 jj(满足 1≤i,j≤2n1 \le i,j \le 2n 且 i≠ji \ne j)。评测系统将返回 11(若 ai=aja_i = a_j),否则返回 00。

请在至多 n+1n+1 次查询内,找出任意一个下标 kk(满足 1≤k≤2n1 \le k \le 2n)使得 ak=0a_k = 0。注意:该交互器是自适应的,即隐藏数组 aa 可能根据你的查询动态变化,但所有变化均不会与之前已给出的查询响应相矛盾。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1031 \le t \le 10^3). The description of the test cases follows.

The first line of each test case contains an integer nn (2≤n≤1042 \le n \le 10^4). The length of the hidden array aa will be 2n2n.

It is guaranteed that the sum of nn over all test cases does not exceed 10410^4.

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

每个测试用例的第一行包含一个整数 nn(2≤n≤1042 \le n \le 10^4)。隐藏数组 aa 的长度为 2n2n。

保证所有测试用例的 nn 值之和不超过 10410^4。

输入输出样例

  • 输入#1

    2
    2
    
    0
    
    1
    
    3
    
    1
    
    0
    
    0

    输出#1

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

说明/提示

In the first example test case, the hidden array aa is [0,1,0,2][0,1,0,2]:

  • In the first query, (i,j)=(1,2)(i,j)=(1,2). Since a1=0a_1=0, a2=1a_2=1, a1≠a2a_1 \ne a_2, the judge responds with 00.
  • In the second query, (i,j)=(3,1)(i,j)=(3,1). Since a3=0a_3=0, a1=0a_1=0, a3=a1a_3 = a_1, the judge responds with 11.
  • The program reports k=3k=3 as an answer. Since a3=0a_3=0, the answer is correct.

In the second example test case, the hidden array aa is [3,2,0,1,0,0][3,2,0,1,0,0]:

  • In the first query, (i,j)=(5,6)(i,j)=(5,6). Since a5=0a_5=0, a6=0a_6=0, a5=a6a_5 = a_6, the judge responds with 11.
  • In the second query, (i,j)=(2,4)(i,j)=(2,4). Since a2=2a_2=2, a4=1a_4=1, a2≠a4a_2 \ne a_4, the judge responds with 00.
  • In the third query, (i,j)=(1,3)(i,j)=(1,3). Since a1=3a_1=3, a3=0a_3=0, a1≠a3a_1 \ne a_3, the judge responds with 00.
  • The program reports k=6k=6 as an answer. Since a6=0a_6=0, the answer is correct.

在第一个样例测试用例中,隐藏数组 aa 为 [0,1,0,2][0,1,0,2]:

  • 在第一次查询中,(i,j)=(1,2)(i,j)=(1,2)。由于 a1=0a_1=0,a2=1a_2=1,且 a1≠a2a_1 \ne a_2,评测系统返回 00。
  • 在第二次查询中,(i,j)=(3,1)(i,j)=(3,1)。由于 a3=0a_3=0,a1=0a_1=0,且 a3=a1a_3 = a_1,评测系统返回 11。
  • 程序报告答案 k=3k=3。由于 a3=0a_3=0,该答案正确。

在第二个样例测试用例中,隐藏数组 aa 为 [3,2,0,1,0,0][3,2,0,1,0,0]:

  • 在第一次查询中,(i,j)=(5,6)(i,j)=(5,6)。由于 a5=0a_5=0,a6=0a_6=0,且 a5=a6a_5 = a_6,评测系统返回 11。
  • 在第二次查询中,(i,j)=(2,4)(i,j)=(2,4)。由于 a2=2a_2=2,a4=1a_4=1,且 a2≠a4a_2 \ne a_4,评测系统返回 00。
  • 在第三次查询中,(i,j)=(1,3)(i,j)=(1,3)。由于 a1=3a_1=3,a3=0a_3=0,且 a1≠a3a_1 \ne a_3,评测系统返回 00。
  • 程序报告答案 k=6k=6。由于 a6=0a_6=0,该答案正确。

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

首页