CF1867E2.Salyg1n and Array (hard version)

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is the hard version of the problem. The only difference between the versions is the limit on the number of queries. In this version, you can make no more than 57 queries. You can make hacks only if both versions of the problem are solved.

This is an interactive problem!

salyg1n has given you a positive integer kk and wants to play a game with you. He has chosen an array of nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \leq a_i \leq 10^9). You must print a1⊕a2⊕…⊕ana_1 \oplus a_2 \oplus \ldots \oplus a_n, where ⊕\oplus denotes the bitwise XOR operation. You can make queries of the following type:

  • ?? ii: in response to this query, you will receive ai⊕ai+1⊕…⊕ai+k−1a_i \oplus a_{i + 1} \oplus \ldots \oplus a_{i + k - 1}. Also, after this query, the subarray ai,ai+1,…,ai+k−1a_i, a_{i + 1}, \ldots, a_{i + k - 1} will be reversed, i.e., the chosen array aa will become: a1,a2,…ai−1,ai+k−1,ai+k−2,…,ai+1,ai,ai+k,…,ana_1, a_2, \ldots a_{i - 1}, a_{i + k - 1}, a_{i + k - 2}, \ldots, a_{i + 1}, a_i, a_{i + k}, \ldots, a_n.

You can make no more than 5757 queries to answer the problem.

这是该问题的困难版本。两个版本的唯一区别在于查询次数限制。在本版本中,你最多只能进行 57 次查询。仅当该问题的两个版本均被解决时,才允许进行 hack。

这是一个交互式问题!

salyg1n 给了你一个正整数 kk,并想和你玩一个游戏。他选择了一个由 nn 个整数组成的数组 a1,a2,…,ana_1, a_2, \ldots, a_n(其中 1≤ai≤1091 \leq a_i \leq 10^9)。你需要输出 a1⊕a2⊕…⊕ana_1 \oplus a_2 \oplus \ldots \oplus a_n,其中 ⊕\oplus 表示按位异或运算。你可以进行如下类型的查询:

  • ?? ii:对于该查询,你将收到 ai⊕ai+1⊕…⊕ai+k−1a_i \oplus a_{i + 1} \oplus \ldots \oplus a_{i + k - 1} 的值。此外,在该查询之后,子数组 ai,ai+1,…,ai+k−1a_i, a_{i + 1}, \ldots, a_{i + k - 1} 将被翻转,即原数组 aa 将变为:a1,a2,…ai−1,ai+k−1,ai+k−2,…,ai+1,ai,ai+k,…,ana_1, a_2, \ldots a_{i - 1}, a_{i + k - 1}, a_{i + k - 2}, \ldots, a_{i + 1}, a_i, a_{i + k}, \ldots, a_n。

你最多只能进行 5757 次查询来解答该问题。

输入格式

The first line contains a single integer tt (1≤t≤10001 \leq t \leq 1000) – the number of test cases.

第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000)——测试用例的数量。

输入输出样例

  • 输入#1

    2
    4 2
    
    6
    
    4
    
    6 6
    
    4

    输出#1

    ? 1
    
    ? 3
    
    ! 2
    
    ? 1
    
    ! 4

说明/提示

In the first test case, the jury has chosen the array aa == [4,2,5,1][4, 2, 5, 1]

In the second test case, the jury has chosen the array aa == [5,7,1,3,3,7][5, 7, 1, 3, 3, 7]

在第一个测试用例中,出题人选择的数组为 aa == [4,2,5,1][4, 2, 5, 1]。

在第二个测试用例中,出题人选择的数组为 aa == [5,7,1,3,3,7][5, 7, 1, 3, 3, 7]。

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

首页