G. Library of Magic time limit per test2 seconds memory limit per test256 megabytes This…
- User
G. Library of Magic time limit per test2 seconds memory limit per test256 megabytes This is an interactive problem.
The Department of Supernatural Phenomena at the Oxenfurt Academy has opened the Library of Magic, which contains the works of the greatest sorcerers of Redania — n (3≤n≤1018 ) types of books, numbered from 1 to n . Each book's type number is indicated on its spine. Moreover, each type of book is stored in the library in exactly two copies! And you have been appointed as the librarian.
One night, you wake up to a strange noise and see a creature leaving the building through a window. Three thick tomes of different colors were sticking out of the mysterious thief's backpack. Before you start searching for them, you decide to compute the numbers a , b , and c written on the spines of these books. All three numbers are distinct.
So, you have an unordered set of tomes, which includes one tome with each of the pairwise distinct numbers a , b , and c , and two tomes for all numbers from 1 to n , except for a , b , and c . You want to find these values a , b , and c .
Since you are not working in a simple library, but in the Library of Magic, you can only use one spell in the form of a query to check the presence of books in their place:
"xor l r" — Bitwise XOR query with parameters l and r . Let k be the number of such tomes in the library whose numbers are greater than or equal to l and less than or equal to r . You will receive the result of the computation v1⊕v2⊕...⊕vk , where v1...vk are the numbers on the spines of these tomes, and ⊕ denotes the operation of bitwise exclusive OR. Since your magical abilities as a librarian are severely limited, you can make no more than 150 queries.
Input The first line of input contains an integer t (1≤t≤300 ) — the number of test cases.
The first line of each test case contains a single integer n (3≤n≤1018 ) — the number of types of tomes.
Interaction The interaction for each test case begins with reading the integer n .
Then you can make up to 150 queries.
To make a query, output a string in the format "xor l r" (without quotes) (1≤l≤r≤n ). After each query, read an integer — the answer to your query.
To report the answer, output a string in the format "ans a b c" (without quotes), where a , b , and c are the numbers you found as the answer to the problem. You can output them in any order.
The interactor is not adaptive, which means that the answer is known before the participant makes queries and does not depend on the queries made by the participant.
After making 150 queries, the answer to any other query will be −1 . Upon receiving such an answer, terminate the program to receive a verdict of "WA" (Wrong answer).
After outputting a query, do not forget to output a newline and flush the output buffer. Otherwise, you will receive a verdict of "IL" (Idleness limit exceeded). To flush the buffer, use:
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.