CF1934D1.XOR Break — Solo Version

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is the solo version of the problem. Note that the solution of this problem may or may not share ideas with the solution of the game version. You can solve and get points for both versions independently.

You can make hacks only if both versions of the problem are solved.

Given an integer variable xx with the initial value of nn. A single break operation consists of the following steps:

  • Choose a value yy such that 0<y<x0 \lt y \lt x and 0<(x⊕y)<x0 \lt (x \oplus y) \lt x.
  • Update xx by either setting x=yx = y or setting x=x⊕yx = x \oplus y.

Determine whether it is possible to transform xx into mm using a maximum of 6363 break operations. If it is, provide the sequence of operations required to achieve x=mx = m.

You don't need to minimize the number of operations.

Here ⊕\oplus denotes the bitwise XOR operation.

这是该问题的单人版本。请注意,本题的解法可能与游戏版本的解法思路相同,也可能不同。你可以独立求解并分别获得两个版本的分数。

仅当两个版本的问题均已被解决时,你才可进行 hack。

给定一个整数变量 xx,其初始值为 nn。一次“break”操作包含以下步骤:

  • 选择一个值 yy,满足 0<y<x0 \lt y \lt x 且 0<(x⊕y)<x0 \lt (x \oplus y) \lt x;
  • 将 xx 更新为 yy 或 x⊕yx \oplus y(即令 x=yx = y 或 x=x⊕yx = x \oplus y)。

请判断是否能在最多 6363 次 break 操作内将 xx 变为 mm。若可以,请给出实现 x=mx = m 所需的操作序列。

你无需最小化操作次数。

此处 ⊕\oplus 表示按位异或运算(bitwise XOR)。

输入格式

The first line contains one positive integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

Each test case consists of a single line containing two integers nn and mm (1≤m<n≤10181 \leq m \lt n \leq 10^{18}) — the initial value of xx and the target value of xx.

第一行包含一个正整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

每个测试用例由一行组成,包含两个整数 nn 和 mm(1≤m<n≤10181 \leq m \lt n \leq 10^{18})—— xx 的初始值和目标值。

输出格式

For each test case, output your answer in the following format.

If it is not possible to achieve mm in 6363 operations, print −1-1.

Otherwise,

The first line should contain kk (1≤k≤631 \leq k \leq 63) — where kk is the number of operations required.

The next line should contain k+1k+1 integers — the sequence where variable xx changes after each break operation. The 11-st and k+1k+1-th integers should be nn and mm, respectively.

对于每个测试用例,请按以下格式输出你的答案:

如果无法在 6363 次操作内得到 mm,则输出 −1-1。

否则:

第一行应包含 kk(1≤k≤631 \leq k \leq 63),其中 kk 为所需的操作次数。

第二行应包含 k+1k+1 个整数——即变量 xx 在每次“break”操作后所经历的序列。第 11 个和第 k+1k+1 个整数应分别为 nn 和 mm。

输入输出样例

  • 输入#1

    3
    7 3
    4 2
    481885160128643072 45035996273704960

    输出#1

    1
    7 3
    -1
    3
    481885160128643072 337769972052787200 49539595901075456 45035996273704960

说明/提示

In the first test case n=7n = 7, for the first operation x=7x = 7 if we choose y=3y = 3 then (7⊕3)<7(7 \oplus 3) \lt 7, hence we can update xx with 33 which is equal to mm.

In the second test case n=4n = 4, for the first operation x=4x = 4.

If we choose:

  • y=1y = 1 then (4⊕1)>4(4 \oplus 1) \gt 4
  • y=2y = 2 then (4⊕2)>4(4 \oplus 2) \gt 4
  • y=3y = 3 then (4⊕3)>4(4 \oplus 3) \gt 4

Hence we can't do the first operation and it is impossible to make x=2x = 2.

在第一个测试用例中,n=7n = 7,第一次操作时 x=7x = 7;若我们选择 y=3y = 3,则 (7⊕3)<7(7 \oplus 3) \lt 7,因此我们可以将 xx 更新为 33,而 33 恰好等于 mm。

在第二个测试用例中,n=4n = 4,第一次操作时 x=4x = 4。

若我们选择:

  • y=1y = 1,则 (4⊕1)>4(4 \oplus 1) \gt 4
  • y=2y = 2,则 (4⊕2)>4(4 \oplus 2) \gt 4
  • y=3y = 3,则 (4⊕3)>4(4 \oplus 3) \gt 4

因此我们无法执行第一次操作,也就不可能使 x=2x = 2。

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

首页