#P12555. [UOI 2024] AND Array

[UOI 2024] AND Array

题目描述

An integer bb and an array of non-negative integers a1,a2,,ana_1,a_2,\ldots,a_n are given. All elements of the array aa are less than 2b2^b.

Let's define f(s,p)f(s, p) (1sn1\le s\le n, 0p<b0\le p < b) 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 2p2^p, AND denotes the bitwise AND\textit{AND} operation, and OR denotes the bitwise OR\textit{OR} operation.

The bitwise AND\textit{AND} of non-negative integers aa and bb 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 aa and bb have ones at that position. For example, 3103_{10} AND 510=001125_{10} = 0011_{2} AND 01012=00012=1100101_{2} = 0001_{2} = 1_{10}.

The bitwise OR\textit{OR} of non-negative integers aa and bb 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 aa and bb have zeros at that position. For example, 3103_{10} OR 510=001125_{10} = 0011_{2} OR 01012=01112=7100101_{2} = 0111_{2} = 7_{10}.

For each ii from 11 to nn, find

f(i,0)+f(i,1)++f(i,b1)f(i,0) + f(i, 1) + \ldots + f(i, b-1)

输入格式

The first line contains two integers nn and bb (1n1051 \leq n \leq 10^5, 1b201 \leq b \leq 20) --- the length of array aa and the limit on the elements of the array, respectively.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (0ai<2b0 \leq a_i < 2^b) --- the elements of array aa.

输出格式

Output nn 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=8f(1,0)=1+2+5=8, f(1,1)=1+3+5=9f(1,1)=1+3+5=9, f(1,2)=1+2+3=6f(1,2)=1+2+3=6, and the first of the required values is equal to 8+9+6=238+9+6 = 23.

Scoring

  • (1010 points): n2000n \leq 2\,000;
  • (1010 points): ai=2ka_i = 2^k, where kk is an integer;
  • (1515 points): b8b \leq 8;
  • (1515 points): b12b \leq 12;
  • (2525 points): b16b \leq 16;
  • (2525 points): without additional constraints.