CF2180E.No Effect XOR
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
In the jungle, there is a lake with infinite lily pads on it. The lily pads are numbered with non-negative integers 0,1,2,3,…. The lily pads with numbers between l and r inclusive are called suitable, while all other lily pads are not suitable for the frogs to sit on.
Currently, a single frog is sitting on each suitable lily pad.
Ostad is watching the lake and wants to reorder the frogs. To do so, Ostad can pick a positive integer x and announce it to the frogs. After hearing the number, the frog sitting on the i-th lily pad will jump to the (i⊕x)-th one, where ⊕ denotes the bitwise XOR operation.
Ostad likes the frogs, and therefore he wants to pick the number x in such a way that all frogs stay within the range of suitable lily pads.
Help Ostad by counting how many different numbers x Ostad can choose such that no frog jumps outside the suitable segment of the lily pads.
在丛林中,有一片湖泊,湖面上有无数片睡莲叶。这些睡莲叶按非负整数编号:0,1,2,3,…。编号在区间 [l,r](含端点)内的睡莲叶被称为“合适”的,其余所有睡莲叶则不适合青蛙落坐。
目前,每片“合适”的睡莲叶上恰好坐着一只青蛙。
Ostad 正在观察这片湖泊,并希望重新安排这些青蛙的位置。为此,Ostad 可以选择一个正整数 x 并向所有青蛙宣布该数。听到该数后,坐在第 i 片睡莲叶上的青蛙将跳到第 (i⊕x) 片睡莲叶上,其中 ⊕ 表示按位异或运算。
Ostad 喜欢这些青蛙,因此他希望选择的 x 满足:所有青蛙跳跃后仍落在“合适”的睡莲叶范围内(即仍在区间 [l,r] 内)。
请帮助 Ostad 计算:有多少个不同的正整数 x 满足上述条件?
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤105). The description of the test cases follows.
For each test case, there is a single line containing two integers l and r (1≤l≤r≤1015).
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤105)。随后是测试用例的描述。
对于每个测试用例,有一行包含两个整数 l 和 r(1≤l≤r≤1015)。
输出格式
For each test case, output a single integer denoting the number of valid values for x.
对于每个测试用例,输出一个整数,表示满足条件的 x 的取值个数。
输入输出样例
输入#1
5 1 2 3 3 2 4 4 7 24189255811072 59373627899903
输出#1
1 0 0 3 2199023255551
说明/提示
In the first test case, x=3 is the only number that Ostad can choose, as 1⊕3=2 and 2⊕3=1, which are within the range [1,2].
There are no valid choices for Ostad in the second and third test cases. For the second case, since we require x>0, the only frog that we have will leave the range. Similarly, in the third case, no valid x exists to keep the frogs within the desired range.
In the fourth test case, Ostad can choose 1, 2, or 3.
在第一个测试用例中,x=3 是 Ostad 唯一可选的数,因为 1⊕3=2 且 2⊕3=1,结果均在区间 [1,2] 内。
在第二个和第三个测试用例中,Ostad 没有合法的选择。对于第二个用例,由于要求 x>0,我们唯一的一只青蛙将离开该区间。类似地,在第三个用例中,不存在任何合法的 x 能使所有青蛙保持在目标区间内。
在第四个测试用例中,Ostad 可以选择 1、2 或 3。
输入解题思路,AI测评打分。不知道怎么写?