CF2190F.Xor Product

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

For non-negative integers x,yx, y and a positive integer kk, let S(x,y,k)S(x, y, k) be the set of values (x+i)⊕(y+j)(x + i) \oplus (y + j) for all 0≤i,j<k0 \le i, j \lt k. Formally: $$ S(x, y, k) = \{ (x + i) \oplus (y + j) \mid 0 \le i, j \lt k \} $$ where ⊕\oplus denotes the bitwise XOR operation.

Define f(x,k)f(x, k) as the maximum size of S(x,y,k)S(x, y, k) over all non-negative integers yy (that is, y≥0y \ge 0).

You are given integers xx and kk. Compute f(x,k)f(x, k).

对于非负整数 x,yx, y 和正整数 kk,定义集合 S(x,y,k)S(x, y, k) 为所有满足 0≤i,j<k0 \le i, j < k 的 (x+i)⊕(y+j)(x + i) \oplus (y + j) 的取值构成的集合。形式化地:

S(x,y,k)={(x+i)⊕(y+j)∣0≤i,j<k}S(x, y, k) = \{ (x + i) \oplus (y + j) \mid 0 \le i, j < k \}

其中 ⊕\oplus 表示按位异或(XOR)运算。

定义 f(x,k)f(x, k) 为:在所有非负整数 yy(即 y≥0y \ge 0)中,S(x,y,k)S(x, y, k) 的最大大小。

给定整数 xx 和 kk,请计算 f(x,k)f(x, k)。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

Each of the next tt lines contains two integers xx and kk (1≤x,k≤10171 \le x, k \le 10^{17}).

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是测试用例的描述。

接下来的 tt 行中,每行包含两个整数 xx 和 kk(1≤x,k≤10171 \le x, k \le 10^{17})。

输出格式

For each test case, output a single integer — the value of f(x,k)f(x, k).

对于每个测试用例,输出一个整数——即 f(x,k)f(x, k) 的值。

输入输出样例

  • 输入#1

    6
    67 1
    7 3
    100 12
    1 1043
    1526 1043
    88946092640567295 100000000000000000

    输出#1

    1
    7
    32
    3128
    4167
    398158383604301822

说明/提示

In the first example, since k=1k=1, the set SS will always contain exactly one element regardless of yy. For instance, if we pick y=69y = 69, we have S(67,69,1)=67⊕69=6S(67, 69, 1) = {67 \oplus 69} = {6}, so ∣S(x,y,k)∣=1|S(x, y, k)| = 1.

In the second example, we have x=7x = 7 and k=3k = 3. The optimal choice is y=8y = 8. The values of (x+i)⊕(y+j)(x + i) \oplus (y + j) are: $$ [7 \oplus 8, 7 \oplus 9, 7 \oplus 10, 8 \oplus 8, 8 \oplus 9, 8 \oplus 10, 9 \oplus 8, 9 \oplus 9, 9 \oplus 10] $$ which simplifies to [15,14,13,0,1,2,1,0,3][15, 14, 13, 0, 1, 2, 1, 0, 3]. The set of distinct values is S(7,8,3)=0,1,2,3,13,14,15S(7, 8, 3) = {0, 1, 2, 3, 13, 14, 15}, so the size is 77. It can be shown that no other yy yields a larger size. However, the choice of yy matters; for example, if you chose y=22y = 22, you would get S(7,22,3)=16,17,30,31S(7, 22, 3) = {16, 17, 30, 31} with size 44, which is suboptimal.

In the sixth example, after countless calculations, we managed to figure out that the optimal yy is 278 302 368 699 121 665278\,302\,368\,699\,121\,665, which gives an answer of 398 158 383 604 301 822398\,158\,383\,604\,301\,822. The proof is left to the reader as a trivial exercise.

在第一个例子中,由于 k=1k=1,集合 SS 无论 yy 取何值都恰好包含一个元素。例如,若取 y=69y = 69,则有 S(67,69,1)={67⊕69}={6}S(67, 69, 1) = \{67 \oplus 69\} = \{6\},因此 ∣S(x,y,k)∣=1|S(x, y, k)| = 1。

在第二个例子中,x=7x = 7 且 k=3k = 3。最优选择为 y=8y = 8。此时 (x+i)⊕(y+j)(x + i) \oplus (y + j) 的所有取值为:

[7⊕8, 7⊕9, 7⊕10, 8⊕8, 8⊕9, 8⊕10, 9⊕8, 9⊕9, 9⊕10][7 \oplus 8,\ 7 \oplus 9,\ 7 \oplus 10,\ 8 \oplus 8,\ 8 \oplus 9,\ 8 \oplus 10,\ 9 \oplus 8,\ 9 \oplus 9,\ 9 \oplus 10]

化简后得到 [15, 14, 13, 0, 1, 2, 1, 0, 3][15,\ 14,\ 13,\ 0,\ 1,\ 2,\ 1,\ 0,\ 3]。其互异值构成的集合为 S(7,8,3)={0, 1, 2, 3, 13, 14, 15}S(7, 8, 3) = \{0,\ 1,\ 2,\ 3,\ 13,\ 14,\ 15\},故集合大小为 77。可以证明,不存在其他 yy 值能使该大小更大。然而,yy 的选取至关重要;例如,若选取 y=22y = 22,则得到 S(7,22,3)={16, 17, 30, 31}S(7, 22, 3) = \{16,\ 17,\ 30,\ 31\},其大小仅为 44,非最优。

在第六个例子中,经过无数次计算,我们最终确定最优的 yy 值为 278 302 368 699 121 665278\,302\,368\,699\,121\,665,对应答案为 398 158 383 604 301 822398\,158\,383\,604\,301\,822。该结论的证明留作读者的一项平凡练习。

输入解题思路,AI测评打分。不知道怎么写?

首页