Problem: 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 of integers which he wants Ashish to guess. Note that is a power of two. Ashish is allowed to ask three different types of queries. They are of the form
- AND : ask for the bitwise AND of elements and ,
- OR : ask for the bitwise OR of elements and ,
- XOR : ask for the bitwise XOR of elements and ,
Can you help Ashish guess the elements of the array?
In this version, each element takes a value in the range (inclusive) and Ashish can ask no more than queries.
Input Format: The first line of input contains one integer — the length of the array. It is guaranteed that is a power of two.
Note: The array in the example is .