#P14664. [KenOI 2025] 异或题

    ID: 14526 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>贪心洛谷原创O2优化位运算构造洛谷比赛

[KenOI 2025] 异或题

Description

Given TT queries, each with a non-negative integer nn. Find two integers aa and bb that satisfy the following conditions:

  • 0a,bn0 \le a,b \le n
  • ab=na \oplus b=n

\oplus means bitwise xor.

Maximize a+ba+b.

Input Format

Each test case contains multiple data sets. You will only receive the score for a test case if you pass all its data sets.

The first line contains an integer TT.

The next TT lines each contains an integer nn.

Output Format

TT lines, each contains an integer representing the maximum of a+ba+b.

6
1
2
3
4
5
6
1
2
3
4
5
8

Hint

Example explanation

There are a total of 66 queries.

  • For the fifth query, a=0,b=na=0,b=n is a possible choice;

  • For the sixth query, a=3,b=5a=3,b=5 is a possible choice.

Data Volume and Conventions

This problem is divided into subtasks. Your score in a subtask is the minimum score across all its test cases.

This problem uses subtask dependencies. You will not receive the score for a subtask unless you achieve full points on all its dependent subtasks.

Subtask TT \le nn \le Score Dependencies
11 1010 2412^4-1 55 none
22 200200 2812^8-1 1010 11
33 10510^5 21612^{16}-1 2020 1,21,2
44 200200 23112^{31}-1 3030
55 10610^6 3535 1,2,3,41,2,3,4

For all of the cases, 1T106,0n23111 \le T \le 10^6,0 \le n \le 2^{31}-1.