#P16779. ⌈Xzy OI R1 T1⌋ 查查编

⌈Xzy OI R1 T1⌋ 查查编

Background

He once said he wished to build a tree that never withers, encoding all memories into nodes, arranged in order starting from the day they first met.

Problem Description

There is a complete binary search tree whose node labels range from aa to bb. Given the label xx of the root node, you need to find the maximum possible value of bb.

Here, a complete binary search tree is a binary tree that satisfies the following properties:

  • For every node, all node labels in its left subtree (if any) are less than the node’s label, and all node labels in its right subtree (if any) are greater than the node’s label.
  • Except for the last level, every level is full, and all nodes on the last level are packed to the left.

Input Format

There are TT test cases.

Each test case gives two integers a,xa, x.

Output Format

For each test case, output one integer bb.

1
1 5
8

Hint

Sample Explanation.

Consider the following tree:


This problem uses bundled tests, meaning you must pass all test points in a subtask to get the score for that subtask.

::cute-table{tuack}

Test Point Score T≤T \le 1≤a≤x≤1 \le a \le x \le Special Constraint
11 2020 8080 10510^5 None.
22 3030 10510^5 101810^{18} x−a=2k−1x - a = 2^k - 1(k≥0k \ge 0)
33 5050 ^ None.

Translated by ChatGPT 5