CF1936A.Bitwise Operation Wizard
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is an interactive problem.
There is a secret sequence p0,p1,…,pn−1, which is a permutation of 0,1,…,n−1.
You need to find any two indices i and j such that pi⊕pj is maximized, where ⊕ denotes the bitwise XOR operation.
To do this, you can ask queries. Each query has the following form: you pick arbitrary indices a, b, c, and d (0≤a,b,c,d<n). Next, the jury calculates x=(pa∣pb) and y=(pc∣pd), where ∣ denotes the bitwise OR operation. Finally, you receive the result of comparison between x and y. In other words, you are told if x<y, x>y, or x=y.
Please find any two indices i and j (0≤i,j<n) such that pi⊕pj is maximum among all such pairs, using at most 3n queries. If there are multiple pairs of indices satisfying the condition, you may output any one of them.
这是一个交互式问题。
存在一个秘密序列 p0,p1,…,pn−1,它是集合 {0,1,…,n−1} 的一个排列。
你需要找出任意两个下标 i 和 j,使得 pi⊕pj 达到最大值,其中 ⊕ 表示按位异或运算。
为此,你可以提出查询。每次查询的形式如下:你任选四个下标 a、b、c、d(满足 0≤a,b,c,d<n)。随后,评测系统计算 x=(pa∣pb) 和 y=(pc∣pd),其中 ∣ 表示按位或运算。最后,你会收到 x 与 y 的比较结果,即被告知 x<y、x>y 或 x=y 中的哪一种情况。
请在至多 3n 次查询内,找出任意一对下标 i 和 j(满足 0≤i,j<n),使得 pi⊕pj 在所有可能的下标对中取到最大值。若存在多个满足条件的下标对,输出其中任意一对即可。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤103). The description of the test cases follows.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤103)。随后是测试用例的描述。
输入输出样例
输入#1
2 4 < = > 2
输出#1
? 0 2 3 1 ? 1 1 2 3 ? 1 2 0 3 ! 3 2 ! 0 1
说明/提示
In the first test case, the hidden permutation is p=[0,3,1,2].
For the query "? 0 2 3 1", the jury return "<" because (p0∣p2)=(0∣1)=1<(p3∣p1)=(2∣3)=3.
For the query "? 1 1 2 3", the jury return "=" because (p1∣p1)=(3∣3)=3=(p2∣p3)=(1∣2)=3.
For the query "? 1 2 0 3", the jury return ">" because (p1∣p2)=(3∣1)=3>(p0∣p3)=(0∣2)=2.
The answer i=3 and j=2 is valid: (p3⊕p2)=(2⊕1)=3 is indeed equal to the maximum possible value of pi⊕pj. Another valid answer would be i=0 and j=1. As the number of queries does not exceed 3n=12, the answer is considered correct.
In the second test case, n=2, so p is either [0,1] or [1,0]. In any case, p0⊕p1=1 is maximum possible.
在第一个测试用例中,隐藏的排列为 p=[0,3,1,2]。
对于查询 "? 0 2 3 1",评测系统返回 "<",因为 (p0∣p2)=(0∣1)=1<(p3∣p1)=(2∣3)=3。
对于查询 "? 1 1 2 3",评测系统返回 "=",因为 (p1∣p1)=(3∣3)=3=(p2∣p3)=(1∣2)=3。
对于查询 "? 1 2 0 3",评测系统返回 ">",因为 (p1∣p2)=(3∣1)=3>(p0∣p3)=(0∣2)=2。
答案 i=3 和 j=2 是合法的:(p3⊕p2)=(2⊕1)=3 确实等于 pi⊕pj 的最大可能值。另一组合法答案为 i=0 和 j=1。由于查询次数不超过 3n=12,该答案被视为正确。
在第二个测试用例中,n=2,因此 p 要么是 [0,1],要么是 [1,0]。无论哪种情况,p0⊕p1=1 均为最大可能值。
输入解题思路,AI测评打分。不知道怎么写?