Greedy CustomerAI (CI翻译)
Problem Statement
You are given positive integers $N,M$ and a sequence of positive integers $A=(A_1,A_2,\ldots,A_N)$ of length $N$.
For a positive integer $k$, define $f(k)$ as the answer to the following problem.
Takahashi has
$k$yen. AtCoder Store has$N$items, and the$i$-th item costs$A_i$yen.He performs the following action for
$i=1,2,\ldots,N$in order.
- If the amount of money he currently has is at least
$A_i$yen, he purchases the$i$-th item.Find the total price of the items he purchased.
Find $\displaystyle \bigoplus_{1\le k\le M} (k\times f(k))$. Here, $\displaystyle \bigoplus_{1\le k\le M} (k\times f(k))$ is defined as the bitwise $\mathrm{XOR}$ of $1\times f(1), 2\times f(2), \ldots, M\times f(M)$.
You are given $T$ test cases; solve each of them.
What is bitwise $\mathrm{XOR}$? The bitwise $\mathrm{XOR}$ of non-negative integers $A$ and $B$, $A \oplus B$, is defined as follows. In the binary representation of $A \oplus B$, the digit at the $2^k$ ($k \geq 0$) place is $1$ if exactly one of the digits at the $2^k$ place in the binary representations of $A$ and $B$ is $1$, and $0$ otherwise. For example, $3 \oplus 5 = 6$ (in binary: $011 \oplus 101 = 110$). In general, the bitwise $\mathrm{XOR}$ of $k$ non-negative integers $p_1, p_2, p_3, \dots, p_k$ is defined as $(\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k)$, and it can be proved that this does not depend on the order of $p_1, p_2, p_3, \dots, p_k$.
Constraints
$1\le T \le 10$$1\le N,M$- The sum of
$N$over all test cases is at most$5\times 10^5$. - The sum of
$M$over all test cases is at most$5\times 10^7$. $1\le A_i \le M$- All input values are integers.
Input
The input is given from Standard Input in the following format:
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
Each test case is given in the following format:
N M
A_1 A_2 \ldots A_N
Output
Output the answers for the test cases in order, separated by newlines.
{"titleZh":"贪心顾客","bodyZh":"## 题目描述\n\n给定正整数 $N,M$,以及一个长度为 $N$ 的正整数序列 $A=(A_1,A_2,\\ldots,A_N)$。\n\n对于正整数 $k$,定义 $f(k)$ 为以下问题的答案。\n\n> 高桥有 $k$ 日元。AtCoder 商店有 $N$ 件商品,第 $i$ 件商品的价格为 $A_i$ 日元。\n> \n> 他按照 $i=1,2,\\ldots,N$ 的顺序执行以下操作。\n> \n> - 如果他当前持有的钱数不少于 $A_i$ 日元,则购买第 $i$ 件商品。\n> \n> 求他购买的所有商品的总价格。\n\n求 $\displaystyle \\bigoplus_{1\\le k\\le M} (k\\times f(k))$。其中,$\displaystyle \\bigoplus_{1\\le k\\le M} (k\\times f(k))$ 定义为 $1\\times f(1), 2\\times f(2), \\ldots, M\\times f(M)$ 的按位 $\mathrm{XOR}$。\n\n给定 $T$ 个测试用例,请分别求出每个测试用例的答案。\n\n按位 $\mathrm{XOR}$ 是什么?非负整数 $A$ 和 $B$ 的按位 $\mathrm{XOR}$ $A \\oplus B$ 定义如下:在 $A \\oplus B$ 的二进制表示中,对于 $2^k$($k \\geq 0$)位,当且仅当 $A$ 和 $B$ 的二进制表示中 $2^k$ 位恰有一个为 $1$ 时,该位为 $1$;否则为 $0$。例如,$3 \\oplus 5 = 6$(二进制表示为:$011 \\oplus 101 = 110$)。一般地,$k$ 个非负整数 $p_1, p_2, p_3, \\dots, p_k$ 的按位 $\mathrm{XOR}$ 定义为 $(\\dots ((p_1 \\oplus p_2) \\oplus p_3) \\oplus \\dots \\oplus p_k)$,可以证明其结果与 $p_1,p_2,p_3, \\dots,p_k$ 的顺序无关。\n\n## 约束条件\n\n- $1\\le T \\le 10$\n- $1\\le N,M$\n- 所有测试用例中 $N$ 的总和不超过 $5\\times 10^5$。\n- 所有测试用例中 $M$ 的总和不超过 $5\\times 10^7$。\n- $1\\le A_i \\le M$\n- 所有输入值均为整数。\n\n## 输入格式\n\n输入从标准输入按以下格式给出:\n\n\n\n## 输出格式\n\n按顺序输出各测试用例的答案,每个答案占一行。"}AI (CI翻译)\nT\n\\text{case}_1\n\\text{case}_2\n\\vdots\n\\text{case}_T\n`\n\n每个测试用例按以下格式给出:\n\n`\nN M\nA_1 A_2 \\ldots A_N\n
样例
3
3 6
2 3 1
5 10
3 1 4 1 5
7 12
4 2 3 4 2 3 3
61
115
190
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。