#abc339g. G - Smaller Sum
G - Smaller Sum
Score: points
问题描述
给定一个长度为 的序列 。
需要回答接下来的 个查询请求。第 个查询如下:
- 找出在 中不超过 的元素之和。
请注意,你需要在线回答这些查询,即只有在回答完当前查询后,下一个查询才会显现。
因此,对于第 个查询,你得到的是加密后的输入 。请按照以下步骤还原原始的第 个查询并作答:
- 定义 ,且令 为(第 个查询的答案)。
- 查询可以通过以下方式解密:
此处, 表示 和 的按位异或操作。
什么是按位异或?非负整数 和 的按位异或运算 定义如下:
- 若 和 在二进制下对应位置上的数字恰好有一个为 ,则 中 位()上的数字为 ,否则为 。
例如:(二进制表示:)。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a sequence of length .
Answer the following queries. The -th query is as follows:
- Find the sum of the elements among that are not greater than .
Here, you need to answer these queries online.
That is, only after you answer the current query is the next query revealed.
For this reason, instead of the -th query itself, you are given encrypted inputs for the query. Restore the original -th query using the following steps and then answer it.
- Let and (the answer to the -th query).
- Then, the query can be decrypted as follows:
Here, denotes the bitwise XOR of and .
What is bitwise XOR? The bitwise XOR of non-negative integers and , , is defined as follows:
- The digit in the place () of in binary is if exactly one of the corresponding digits of and in binary is , and otherwise.
For example, (in binary: ).
Constraints
- All input values are integers.
- For the encrypted inputs, the following holds:
- For the decrypted queries, the following holds:
Input
The input is given from Standard Input in the following format:
Output
Print lines.
The -th line should contain the answer to the -th query.
Sample Input 1
8
2 0 2 4 0 2 0 3
5
1 8 3
10 12 11
3 3 2
3 6 5
12 0 11
Sample Output 1
9
2
0
8
5
The given sequence is .
This input contains five queries.
- Initially, .
- The first query is .
- After decryption, we get $L_i = \alpha \oplus B_0 = 1, R_i = \beta \oplus B_0 = 8, X_i = \gamma \oplus B_0 = 3$.
- The answer to this query is . This becomes .
- The next query is .
- After decryption, we get $L_i = \alpha \oplus B_1 = 3, R_i = \beta \oplus B_1 = 5, X_i = \gamma \oplus B_1 = 2$.
- The answer to this query is . This becomes .
- The next query is .
- After decryption, we get $L_i = \alpha \oplus B_2 = 1, R_i = \beta \oplus B_2 = 1, X_i = \gamma \oplus B_2 = 0$.
- The answer to this query is . This becomes .
- The next query is .
- After decryption, we get $L_i = \alpha \oplus B_3 = 3, R_i = \beta \oplus B_3 = 6, X_i = \gamma \oplus B_3 = 5$.
- The answer to this query is . This becomes .
- The next query is .
- After decryption, we get $L_i = \alpha \oplus B_4 = 4, R_i = \beta \oplus B_4 = 8, X_i = \gamma \oplus B_4 = 3$.
- The answer to this query is . This becomes .
update @ 2024/3/10 01:32:16