#4619. [UOI 2024] AND Array
[UOI 2024] AND Array
[UOI 2024] AND Array
题目描述
An integer $b$ and an array of non-negative integers $a_1,a_2,\ldots,a_n$ are given. All elements of the array $a$ are less than $2^b$.Let's define (, ) as the result of the following pseudocode:
res = 0
x = power(2, p)
for i = s to n:
if ((x AND a[i]) == 0):
x = (x OR a[i])
res = res + i
return res
Here, power(2, p) denotes , AND denotes the bitwise operation, and OR denotes the bitwise operation.
The bitwise of non-negative integers and is equal to a non-negative integer, in which the binary representation has a one at a certain position only if both binary representations of and have ones at that position. For example, AND AND .
The bitwise of non-negative integers and is equal to a non-negative integer, in which the binary representation has a zero at a certain position only if both binary representations of and have zeros at that position. For example, OR OR .
For each from to , find
输入格式
The first line contains two integers $n$ and $b$ ($1 \leq n \leq 10^5$, $1 \leq b \leq 20$) --- the length of array $a$ and the limit on the elements of the array, respectively.The second line contains integers () --- the elements of array .
输出格式
Output $n$ integers --- the required values.5 3
0 2 1 3 4
23 20 16 14 10
3 2
1 3 2
4 3 3
提示
In the first example, $f(1,0)=1+2+5=8$, $f(1,1)=1+3+5=9$, $f(1,2)=1+2+3=6$, and the first of the required values is equal to $8+9+6 = 23$.Scoring
- ( points): ;
- ( points): , where is an integer;
- ( points): ;
- ( points): ;
- ( points): ;
- ( points): without additional constraints. 标签: P12555|2024|UOI(乌克兰)