QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 1024 MB Total points: 100
Statistics

NIT 喜欢圆螺丝。他也喜欢 $\oplus$ 运算符,因为这让他联想到圆螺丝,其中 $\oplus$ 表示按位异或(Bitwise-XOR)运算。

定义一个序列 $a_1, a_2, \dots, a_n$ 的值 $V_a$ 为: $$V_a = a_1 + a_n + \sum_{i=1}^{n-1} (a_i \oplus a_{i+1})$$

给定一个序列 $a_1, a_2, \dots, a_n$,你可以进行任意次数的以下操作:

  • 选择一个下标 $i$($1 \le i \le n$),将 $a_i$ 修改为任意非负整数;该操作的代价为 $C$。

你需要最小化序列的值与操作所产生的代价之和。换句话说,设 $p$ 为你进行的操作次数,$V_{a'}$ 为操作后序列 $a$ 的值,你需要最小化 $pC + V_{a'}$。

输入格式

输入包含多个测试用例。输入的第一行包含一个整数 $T$($1 \le T \le 100$),表示测试用例的数量。

对于每个测试用例: 第一行包含两个整数 $n, C$($2 \le n \le 10^5, 0 \le C < 2^{19}$),分别表示序列的长度和进行一次操作的代价。

第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$($0 \le a_i < 2^{18}$),表示序列中的元素。

保证所有测试用例中 $n$ 的总和不超过 $2 \times 10^5$。

输出格式

对于每个测试用例,在一行中输出一个整数,表示 $pC + V_{a'}$ 的最小可能值。

样例

输入样例 1

3
4 4
1 4 5 6
8 6
6 6 6 1 1 6 6 6
6 7
1 7 2 6 3 5

输出样例 1

14
24
29

说明

对于第一个测试用例,达到最小值的一种方法是将序列修改为 $1, \mathbf{1}, \mathbf{1}, \mathbf{0}$;加粗的数字是经过修改的。最终序列的值为 $2$,进行了 $3$ 次操作;总值 + 代价为 $2 + 3 \times 4 = 14$。

对于第二个测试用例,达到最小值的一种方法是将序列修改为 $6, 6, 6, \mathbf{6}, \mathbf{6}, 6, 6, 6$;最终序列的值为 $12 + 2 \times 6 = 24$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.