CF2146D1.Max Sum OR (Easy Version)

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is the easy version of the problem. The difference between the versions is that in this version, l=0l=0, and r<2⋅105r \lt 2\cdot 10^5. You can hack only if you solved all versions of this problem.

You are given two integers ll and rr (l≤rl\le r).

Let n=r−l+1n = r - l + 1. We will create two arrays aa and bb, both consisting of nn integers. Initially, both aa and bb are equal to [l,l+1,…,r][l, l+1, \ldots, r]. You have to reorder the array aa arbitrarily to maximize the following value:

sum_i=1nleft(a_i;∣;b_iright).\\sum\_{i=1}^n \\left (a\_i\\;|\\;b\_i \\right ).

Here, ∣| denotes the bitwise OR operation.

You also need to construct a possible way to reorder the array aa.

这是该问题的简单版本。两个版本的区别在于,在此版本中,l=0l=0,且 r<2⋅105r < 2\cdot 10^5。仅当您已解决该问题的所有版本时,才可进行 hack。

给定两个整数 ll 和 rr(满足 l≤rl \le r)。

令 n=r−l+1n = r - l + 1。我们将构造两个长度均为 nn 的整数数组 aa 和 bb。初始时,aa 和 bb 均等于 [l,l+1,…,r][l, l+1, \ldots, r]。您需要对数组 aa 进行任意重排,以最大化以下值:

∑i=1n(ai  ∣  bi).\sum_{i=1}^n \left (a_i\;|\;b_i \right ).

其中,∣| 表示按位或运算。

您还需构造一种使数组 aa 达到该最大值的重排方案。

输入格式

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.

The only line of each test case contains two integers ll and rr (0=l≤r<2⋅1050=l\leq r \lt 2\cdot 10^5) — the minimum and maximum elements in aa.

Let n=r−l+1n = r - l + 1. It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052\cdot 10^5.

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

每个测试用例仅有一行,包含两个整数 ll 和 rr(0=l≤r<2⋅1050=l\leq r \lt 2\cdot 10^5)——即数组 aa 中的最小值和最大值。

令 n=r−l+1n = r - l + 1。保证所有测试用例的 nn 之和不超过 2⋅1052\cdot 10^5。

输出格式

For each test case, print a single integer in the first line of output — the maximum value of ∑i=1n(ai  ∣  bi)\sum\limits_{i=1}^n \left (a_i\;|\;b_i \right ).

Then, print nn distinct integers a1,a2,…,ana_1, a_2, \ldots,a_n in the second line — the array aa after reordering.

If there are multiple answers, you may print any of them.

对于每个测试用例,在输出的第一行打印一个整数——∑i=1n(ai  ∣  bi)\sum\limits_{i=1}^n \left (a_i\;|\;b_i \right ) 的最大值。

然后,在第二行打印 nn 个互不相同的整数 a1,a2,…,ana_1, a_2, \ldots,a_n——重排后的数组 aa。

如果存在多个答案,你可以输出其中任意一个。

输入输出样例

  • 输入#1

    3
    0 3
    0 9
    0 15

    输出#1

    12
    3 2 1 0 
    90
    7 8 5 4 3 2 9 0 1 6
    240
    15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

说明/提示

In the first test case, the reordered array aa is [3,2,1,0][3,2,1,0]. The value of the expression is (3  ∣  0)+(2  ∣  1)+(1  ∣  2)+(0  ∣  3)=3+3+3+3=12(3\;|\;0)+(2\;|\;1)+(1\;|\;2)+(0\;|\;3)=3+3+3+3=12. It can be proved that this is the maximum possible value of the expression.

In the second test case, the reordered array aa is [7,8,5,4,3,2,9,0,1,6][7,8,5,4,3,2,9,0,1,6]. The value of the expression is 9090. It can be proved that this is the maximum possible value of the expression.

在第一个测试用例中,重排后的数组 aa 为 [3,2,1,0][3,2,1,0]。该表达式的值为 (3  ∣  0)+(2  ∣  1)+(1  ∣  2)+(0  ∣  3)=3+3+3+3=12(3\;|\;0)+(2\;|\;1)+(1\;|\;2)+(0\;|\;3)=3+3+3+3=12。可以证明这是该表达式可能取得的最大值。

在第二个测试用例中,重排后的数组 aa 为 [7,8,5,4,3,2,9,0,1,6][7,8,5,4,3,2,9,0,1,6]。该表达式的值为 9090。可以证明这是该表达式可能取得的最大值。

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

首页