0% found this document useful (0 votes)
53 views1 page

Interval Xor

Mr. X enjoys bitwise operations and proposed a challenge at a New Year's party to calculate the bitwise XOR of integers in an interval [0, ai] and the maximum XOR possible by removing one integer from the interval. The input specifies the number of queries q and each query's interval ai. For each query, the output should provide the XOR of the interval and maximum XOR possible after removing one integer. Sample input and output are provided for explanation.

Uploaded by

Mihail Livadaru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views1 page

Interval Xor

Mr. X enjoys bitwise operations and proposed a challenge at a New Year's party to calculate the bitwise XOR of integers in an interval [0, ai] and the maximum XOR possible by removing one integer from the interval. The input specifies the number of queries q and each query's interval ai. For each query, the output should provide the XOR of the interval and maximum XOR possible after removing one integer. Sample input and output are provided for explanation.

Uploaded by

Mihail Livadaru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Interval Xor

Input file: standard input


Output file: standard output
Time limit: 0.5 seconds
Memory limit: 64 megabytes

Mr. X enjoys solving and especially talking a lot about bitwise operations, even at the New Year’s Day
party. While drinking with his friends, he came up with the following challenge:
There are q queries, and in each query you are given a positive integer ai (i = 0 . . . q − 1). You are required
to answer the following question:
What is the bitwise XOR of the integers in the interval [0, ai ] and what is the maximum bitwise XOR we
can get by removing exactly one integer from that interval?
Your task is to solve the challenge of Mr. X.

Input
The first line of the input will contain q, the number of queries (1 ≤ q ≤ 2 ∗ 105 ).
Each of the next q lines contains a positive integer ai , describing a query. (1 ≤ ai ≤ 109 ).
For tests worth 15 points, (1 ≤ q, ai ≤ 1000).
For tests worth 15 more points, (1 ≤ ai ≤ 104 ).
For tests worth 20 more points, (1 ≤ ai ≤ 106 ), (1 ≤ q ≤ 50).

Output
You need to write q lines, the answers to each query. Every line should contain two numbers, namely, the
bitwise XOR of the integers in the interval [0, ai ], and the maximum bitwise XOR we can get by removing
one integer from the interval.

Example
standard input standard output
5 1 29
29 15 15
14 1 9
9 12 15
12 0 31
31

Page 1 of 1

You might also like