CF1451E2.Bitwise Queries (Hard Version)
提高+/省选-
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The only difference between the easy and hard versions is the constraints on the number of queries.
This is an interactive problem.
Ridbit has a hidden array a of n integers which he wants Ashish to guess. Note that n is a power of two. Ashish is allowed to ask three different types of queries. They are of the form
- AND i j: ask for the bitwise AND of elements ai and aj (1≤i,j≤n, i=j)
- OR i j: ask for the bitwise OR of elements ai and aj (1≤i,j≤n, i=j)
- XOR i j: ask for the bitwise XOR of elements ai and aj (1≤i,j≤n, i=j)
Can you help Ashish guess the elements of the array?
In this version, each element takes a value in the range [0,n−1] (inclusive) and Ashish can ask no more than n+1 queries.
简单版本与困难版本的唯一区别在于查询次数的限制。
这是一道交互式题目。
Ridbit 有一个长度为 n 的隐藏数组 a(其中每个元素均为整数),他希望 Ashish 猜出该数组。注意,n 是 2 的幂次。Ashish 可以提出三种不同类型的查询,形式如下:
AND i j:询问元素 ai 与 aj 的按位与结果(其中 1≤i,j≤n,且 i=j);OR i j:询问元素 ai 与 aj 的按位或结果(其中 1≤i,j≤n,且 i=j);XOR i j:询问元素 ai 与 aj 的按位异或结果(其中 1≤i,j≤n,且 i=j)。
你能否帮助 Ashish 推断出数组的所有元素?
在本版本中,每个元素的取值范围为 [0,n−1](含端点),且 Ashish 最多只能进行 n+1 次查询。
输入格式
The first line of input contains one integer n (4≤n≤216) — the length of the array. It is guaranteed that n is a power of two.
输入的第一行包含一个整数 n (4≤n≤216) —— 数组的长度。保证 n 是 2 的幂。
输入输出样例
输入#1
4 0 2 3
输出#1
OR 1 2 OR 2 3 XOR 2 4 ! 0 0 2 3
说明/提示
The array a in the example is [0,0,2,3].
示例中的数组 a 为 [0,0,2,3]。
输入解题思路,AI测评打分。不知道怎么写?