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=0, and r<2⋅105. You can hack only if you solved all versions of this problem.
You are given two integers l and r (l≤r).
Let n=r−l+1. We will create two arrays a and b, both consisting of n integers. Initially, both a and b are equal to [l,l+1,…,r]. You have to reorder the array a arbitrarily to maximize the following value:
sum_i=1nleft(a_i;∣;b_iright).
Here, ∣ denotes the bitwise OR operation.
You also need to construct a possible way to reorder the array a.
这是该问题的简单版本。两个版本的区别在于,在此版本中,l=0,且 r<2⋅105。仅当您已解决该问题的所有版本时,才可进行 hack。
给定两个整数 l 和 r(满足 l≤r)。
令 n=r−l+1。我们将构造两个长度均为 n 的整数数组 a 和 b。初始时,a 和 b 均等于 [l,l+1,…,r]。您需要对数组 a 进行任意重排,以最大化以下值:
i=1∑n(ai∣bi).
其中,∣ 表示按位或运算。
您还需构造一种使数组 a 达到该最大值的重排方案。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The only line of each test case contains two integers l and r (0=l≤r<2⋅105) — the minimum and maximum elements in a.
Let n=r−l+1. It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例仅有一行,包含两个整数 l 和 r(0=l≤r<2⋅105)——即数组 a 中的最小值和最大值。
令 n=r−l+1。保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, print a single integer in the first line of output — the maximum value of i=1∑n(ai∣bi).
Then, print n distinct integers a1,a2,…,an in the second line — the array a after reordering.
If there are multiple answers, you may print any of them.
对于每个测试用例,在输出的第一行打印一个整数——i=1∑n(ai∣bi) 的最大值。
然后,在第二行打印 n 个互不相同的整数 a1,a2,…,an——重排后的数组 a。
如果存在多个答案,你可以输出其中任意一个。
输入输出样例
输入#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 a is [3,2,1,0]. The value of the expression is (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 a is [7,8,5,4,3,2,9,0,1,6]. The value of the expression is 90. It can be proved that this is the maximum possible value of the expression.
在第一个测试用例中,重排后的数组 a 为 [3,2,1,0]。该表达式的值为 (3∣0)+(2∣1)+(1∣2)+(0∣3)=3+3+3+3=12。可以证明这是该表达式可能取得的最大值。
在第二个测试用例中,重排后的数组 a 为 [7,8,5,4,3,2,9,0,1,6]。该表达式的值为 90。可以证明这是该表达式可能取得的最大值。
输入解题思路,AI测评打分。不知道怎么写?