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 aa of nn integers which he wants Ashish to guess. Note that nn is a power of two. Ashish is allowed to ask three different types of queries. They are of the form

  • AND ii jj: ask for the bitwise AND of elements aia_i and aja_j (1≤i,j≤n(1 \leq i, j \le n, i≠j)i \neq j)
  • OR ii jj: ask for the bitwise OR of elements aia_i and aja_j (1≤i,j≤n(1 \leq i, j \le n, i≠j)i \neq j)
  • XOR ii jj: ask for the bitwise XOR of elements aia_i and aja_j (1≤i,j≤n(1 \leq i, j \le n, i≠j)i \neq 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][0, n-1] (inclusive) and Ashish can ask no more than n+1n+1 queries.

简单版本与困难版本的唯一区别在于查询次数的限制。

这是一道交互式题目。

Ridbit 有一个长度为 nn 的隐藏数组 aa(其中每个元素均为整数),他希望 Ashish 猜出该数组。注意,nn 是 22 的幂次。Ashish 可以提出三种不同类型的查询,形式如下:

  • AND i j:询问元素 aia_i 与 aja_j 的按位与结果(其中 1≤i,j≤n1 \leq i, j \le n,且 i≠ji \neq j);
  • OR i j:询问元素 aia_i 与 aja_j 的按位或结果(其中 1≤i,j≤n1 \leq i, j \le n,且 i≠ji \neq j);
  • XOR i j:询问元素 aia_i 与 aja_j 的按位异或结果(其中 1≤i,j≤n1 \leq i, j \le n,且 i≠ji \neq j)。

你能否帮助 Ashish 推断出数组的所有元素?

在本版本中,每个元素的取值范围为 [0,n−1][0, n-1](含端点),且 Ashish 最多只能进行 n+1n+1 次查询。

输入格式

The first line of input contains one integer nn (4≤n≤216)(4 \le n \le 2^{16}) — the length of the array. It is guaranteed that nn is a power of two.

输入的第一行包含一个整数 nn (4≤n≤216)(4 \le n \le 2^{16}) —— 数组的长度。保证 nn 是 22 的幂。

输入输出样例

  • 输入#1

    4
    
    0
    
    2
    
    3

    输出#1

    OR 1 2
    
    OR 2 3
    
    XOR 2 4
    
    ! 0 0 2 3

说明/提示

The array aa in the example is [0,0,2,3][0, 0, 2, 3].

示例中的数组 aa 为 [0,0,2,3][0, 0, 2, 3]。

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

首页