CF1534E.Lost Array

提高+/省选-

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is an interactive problem.

Note: the XOR-sum of an array a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9) is defined as a1⊕a2⊕…⊕ana_1 \oplus a_2 \oplus \ldots \oplus a_n, where ⊕\oplus denotes the bitwise XOR operation.

Little Dormi received an array of nn integers a1,a2,…,ana_1, a_2, \ldots, a_n for Christmas. However, while playing with it over the winter break, he accidentally dropped it into his XOR machine, and the array got lost.

The XOR machine is currently configured with a query size of kk (which you cannot change), and allows you to perform the following type of query: by giving the machine kk distinct indices x1,x2,…,xkx_1, x_2, \ldots, x_k, it will output ax1⊕ax2⊕…⊕axka_{x_1} \oplus a_{x_2} \oplus \ldots \oplus a_{x_k}.

As Little Dormi's older brother, you would like to help him recover the XOR-sum of his array a1,a2,…,ana_1, a_2, \ldots, a_n by querying the XOR machine.

Little Dormi isn't very patient, so to be as fast as possible, you must query the XOR machine the minimum number of times to find the XOR-sum of his array. Formally, let dd be the minimum number of queries needed to find the XOR-sum of any array of length nn with a query size of kk. Your program will be accepted if you find the correct XOR-sum in at most dd queries.

Lastly, you also noticed that with certain configurations of the machine kk and values of nn, it may not be possible to recover the XOR-sum of Little Dormi's lost array. If that is the case, you should report it as well.

The array a1,a2,…,ana_1, a_2, \ldots, a_n is fixed before you start querying the XOR machine and does not change with the queries.

这是一个交互式问题。

注意:数组 a1,a2,…,ana_1, a_2, \ldots, a_n(其中 1≤ai≤1091 \le a_i \le 10^9)的**异或和(XOR-sum)**定义为 a1⊕a2⊕…⊕ana_1 \oplus a_2 \oplus \ldots \oplus a_n,其中 ⊕\oplus 表示按位异或运算(bitwise XOR operation)。

小 Dormi 在圣诞节收到了一个包含 nn 个整数的数组 a1,a2,…,ana_1, a_2, \ldots, a_n。然而,在寒假期间玩耍时,他不小心将该数组掉进了他的异或机(XOR machine)里,结果数组丢失了。

当前,该异或机被配置为查询大小为 kk(此参数不可更改),并允许你执行如下类型的查询:向机器提供 kk 个互不相同的下标 x1,x2,…,xkx_1, x_2, \ldots, x_k,机器将返回 ax1⊕ax2⊕…⊕axka_{x_1} \oplus a_{x_2} \oplus \ldots \oplus a_{x_k}。

作为小 Dormi 的哥哥,你希望借助该异或机,帮他恢复原数组 a1,a2,…,ana_1, a_2, \ldots, a_n 的异或和。

小 Dormi 并没有太多耐心,因此为了尽可能快地完成任务,你必须以最少的查询次数来确定该数组的异或和。形式化地说,令 dd 表示:对任意长度为 nn 的数组,在查询大小为 kk 的约束下,为确定其异或和所需的最少查询次数。若你的程序能在至多 dd 次查询内正确求出异或和,则视为通过。

最后,你还注意到:在某些异或机配置(即特定的 kk 值)与数组长度 nn 的组合下,可能根本无法恢复小 Dormi 丢失数组的异或和。若出现这种情况,你也应予以报告。

数组 a1,a2,…,ana_1, a_2, \ldots, a_n 在你开始查询异或机之前即已固定,且在后续查询过程中不会发生任何改变。

输入格式

The only line of input contains the integers nn and kk (1≤n≤5001 \le n \le 500, 1≤k≤n1 \le k \le n), the length of the lost array and the configured query size of the XOR machine.

Elements of the original array satisfy 1≤ai≤1091 \le a_i \le 10^9.

It can be proven that that if it is possible to recover the XOR sum under the given constraints, it can be done in at most 500500 queries. That is, d≤500d \le 500.

After taking nn and kk, begin interaction.

输入仅有一行,包含两个整数 nn 和 kk(1≤n≤5001 \le n \le 500,1≤k≤n1 \le k \le n),分别表示丢失数组的长度以及 XOR 机器所配置的查询大小。

原数组的元素满足 1≤ai≤1091 \le a_i \le 10^9。

可以证明:若在给定约束下能够恢复 XOR 和,则至多需要 500500 次查询即可完成,即 d≤500d \le 500。

读入 nn 和 kk 后,开始交互。

输出格式

If it is impossible to recover the XOR-sum of the array, output −1-1 immediately after taking nn and kk. Do not begin interaction.

Otherwise, when your program finds the XOR-sum of the lost array a1,a2,…,ana_1, a_2, \ldots, a_n, report the answer in the following format: "! x", where xx is the XOR sum of the array a1,a2,…,ana_1, a_2, \ldots, a_n, and terminate your program normally immediately after flushing the output stream.

Note that answering does not count as a query.

如果无法恢复该数组的异或和,请在读取 nn 和 kk 后立即输出 −1-1,且不得开始交互。

否则,当你的程序求出丢失数组 a1,a2,…,ana_1, a_2, \ldots, a_n 的异或和后,请以下列格式报告答案:“! x”,其中 xx 为数组 a1,a2,…,ana_1, a_2, \ldots, a_n 的异或和,并在刷新输出流后立即正常终止程序。

注意:提交答案不计入查询次数。

输入输出样例

  • 输入#1

    5 3
    
    4
    
    0
    
    1

    输出#1

    ? 1 2 3
    
    ? 2 3 5
    
    ? 4 1 5
    
    ! 7
  • 输入#2

    3 2

    输出#2

    -1

说明/提示

In the first example interaction, the array a1,a2,…,ana_1, a_2, \ldots, a_n is 2,1,7,5,62, 1, 7, 5, 6 and its XOR-sum is 77.

The first query made asks for indices 1,2,31,2,3, so the response is a1⊕a2⊕a3=2⊕1⊕7=4a_1 \oplus a_2 \oplus a_3 = 2 \oplus 1 \oplus 7 = 4.

The second query made asks for indices 2,3,52,3,5, so the response is a2⊕a3⊕a5=1⊕7⊕6=0a_2 \oplus a_3 \oplus a_5 = 1 \oplus 7 \oplus 6 = 0.

The third query made asks for indices 4,1,54,1,5, so the response is a4⊕a1⊕a5=5⊕2⊕6=1a_4 \oplus a_1 \oplus a_5 = 5 \oplus 2 \oplus 6 = 1. Note that the indices may be output in any order.

Additionally, even though three queries were made in the example interaction, it is just meant to demonstrate the interaction format and does not necessarily represent an optimal strategy.

In the second example interaction, there is no way to recover the XOR-sum of Little Dormi's array no matter what is queried, so the program immediately outputs −1-1 and exits.

在第一个示例交互中,数组 a1,a2,…,ana_1, a_2, \ldots, a_n 为 2,1,7,5,62, 1, 7, 5, 6,其异或和(XOR-sum)为 77。

第一次查询请求索引 1,2,31,2,3,因此响应为 a1⊕a2⊕a3=2⊕1⊕7=4a_1 \oplus a_2 \oplus a_3 = 2 \oplus 1 \oplus 7 = 4。

第二次查询请求索引 2,3,52,3,5,因此响应为 a2⊕a3⊕a5=1⊕7⊕6=0a_2 \oplus a_3 \oplus a_5 = 1 \oplus 7 \oplus 6 = 0。

第三次查询请求索引 4,1,54,1,5,因此响应为 a4⊕a1⊕a5=5⊕2⊕6=1a_4 \oplus a_1 \oplus a_5 = 5 \oplus 2 \oplus 6 = 1。注意:索引的输出顺序可以是任意的。

此外,尽管该示例交互中进行了三次查询,但这仅用于演示交互格式,并不一定代表最优策略。

在第二个示例交互中,无论查询哪些索引,都无法恢复 Little Dormi 数组的异或和,因此程序立即输出 −1-1 并退出。

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

首页