CF1617D2.Too Many Impostors (hard version)

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is an interactive problem. The only difference between the easy and hard version is the limit on number of questions.

There are nn players labelled from 11 to nn. It is guaranteed that nn is a multiple of 33.

Among them, there are kk impostors and n−kn-k crewmates. The number of impostors, kk, is not given to you. It is guaranteed that n3<k<2n3\frac{n}{3} \lt k \lt \frac{2n}{3}.

In each question, you can choose three distinct integers aa, bb, cc (1≤a,b,c≤n1 \le a, b, c \le n) and ask: "Among the players labelled aa, bb and cc, are there more impostors or more crewmates?" You will be given the integer 00 if there are more impostors than crewmates, and 11 otherwise.

Find the number of impostors kk and the indices of players that are impostors after asking at most n+6n+6 questions.

The jury is adaptive, which means the indices of impostors may not be fixed beforehand and can depend on your questions. It is guaranteed that there is at least one set of impostors which fulfills the constraints and the answers to your questions at any time.

这是一个交互式问题。简单版本与困难版本的唯一区别在于提问次数的限制。

有 nn 名玩家,编号从 11 到 nn。保证 nn 是 33 的倍数。

其中,有 kk 名伪装者(impostors)和 n−kn-k 名船员(crewmates)。伪装者的数量 kk 不会提供给你。保证 n3<k<2n3\frac{n}{3} \lt k \lt \frac{2n}{3}。

每次提问时,你可以选择三个互不相同的整数 aa、bb、cc(满足 1≤a,b,c≤n1 \le a, b, c \le n),并提出如下问题:“在编号为 aa、bb 和 cc 的玩家中,是伪装者更多,还是船员更多?” 若伪装者人数多于船员人数,则你会收到整数 00;否则(即船员人数不少于伪装者人数),你会收到整数 11。

你需要在至多 n+6n+6 次提问内,确定伪装者人数 kk 以及所有伪装者的编号。

评测机是自适应的(adaptive),这意味着伪装者的编号并非预先固定,而可能依赖于你所提出的提问。但保证:在任意时刻,总存在至少一组满足约束条件的伪装者集合,使其与你已获得的所有回答一致。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1001 \le t \le 100). Description of the test cases follows.

The first and only line of each test case contains a single integer nn (6≤n<1046 \le n \lt 10^4, nn is a multiple of 33) — the number of players.

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

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

每个测试用例仅有一行,包含一个整数 nn(6≤n<1046 \le n \lt 10^4,且 nn 是 33 的倍数)—— 表示玩家数量。

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

输入输出样例

  • 输入#1

    2
    6
    
    0
    
    1
    
    9
    
    1

    输出#1

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

说明/提示

Explanation for example interaction (note that this example only exists to demonstrate the interaction procedure and does not provide any hint for the solution):

For the first test case:

Question "? 1 2 3" returns 00, so there are more impostors than crewmates among players 11, 22 and 33.

Question "? 3 4 5" returns 11, so there are more crewmates than impostors among players 33, 44 and 55.

Outputting "! 3 4 1 2" means that one has found all the impostors, by some miracle. There are k=3k = 3 impostors. The players who are impostors are players 44, 11 and 22.

For the second test case:

Question "? 7 1 9" returns 11, so there are more crewmates than impostors among players 77, 11 and 99.

Outputting "! 4 2 3 6 8" means that one has found all the impostors, by some miracle. There are k=4k = 4 impostors. The players who are impostors are players 22, 33, 66 and 88.

示例交互说明(注意:该示例仅用于演示交互流程,不提供任何解题提示):

对于第一个测试用例:

询问 “? 1 2 3” 返回 00,说明玩家 11、22 和 33 中,冒名顶替者(impostor)人数多于船员(crewmate)人数。

询问 “? 3 4 5” 返回 11,说明玩家 33、44 和 55 中,船员人数多于冒名顶替者人数。

输出 “! 3 4 1 2” 表示某人奇迹般地找出了全部冒名顶替者。此时冒名顶替者人数为 k=3k = 3,冒名顶替者为玩家 44、11 和 22。

对于第二个测试用例:

询问 “? 7 1 9” 返回 11,说明玩家 77、11 和 99 中,船员人数多于冒名顶替者人数。

输出 “! 4 2 3 6 8” 表示某人奇迹般地找出了全部冒名顶替者。此时冒名顶替者人数为 k=4k = 4,冒名顶替者为玩家 22、33、66 和 88。

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

首页