Broken Address Bus

시간 제한1초메모리 제한1024 MB

요약
주어진 마스크에 포함된 비트만 사용하는 주소들의 메모리 값 합을 각 질의마다 구한다.
난이도

어려움10점 중 8점

유형
비트 연산, 동적 계획법
정답자
아직 제출이 없습니다

문제

The memory in Juku's computer has NN cells, addressed by numbers 0…N−10 \ldots N-1. To read the value from a cell, you first have to put the cell's address on the address bus. The address bus consists of 1616 parallel wires---one for each bit of the address. E.g., to read the value at the address 1919, you first write 1919 out in binary---19=24+21+20=(10011)_219 = 2^4 + 2^1 + 2^0 = (10011)\_2---and then put voltage on wires 44, 11, and 00. To read from the address 00, you don't put voltage on any of the wires.

However, some wires are broken---when you put voltage on any of them, the memory chip will not register it. E.g, if the wire 00 is broken, you cannot read from the address 7=22+21+207 = 2^2 + 2^1 + 2^0 because it requires voltage on the wire 00. On the other hand, you still can read from 6=22+216 = 2^2 + 2^1.

Given the contents of the memory and the set of all intact wires, compute the sum of all the values you can read.

입력

The first line of input contains NN (1≤N≤2161 \le N \le 2^{16}), the number of values in memory, and QQ (1≤Q≤1051 \le Q \le 10^5), the number of queries. The next NN lines contain the values in memory cells, from 00 to N−1N-1, one per line. Each value is a non-negative integer not larger than 10910^9. The last QQ lines contain the queries. Each query gives the address X_iX\_i (0≤X_i<2160 \le X\_i < 2^{16}) that you get when you put voltage on all the wires that are not broken.

출력

The output must contain QQ lines, each with the answer to the corresponding query: the sum of the values that can be read from the memory if the set of working address bus wires is as given in the query parameter X_iX\_i.

힌트

In the query '0', all wires are broken, and only the value 1010 at address 00 is readable.

In the query '15', the first 44 wires are working and all values are readable.

In the last query, only the values 1010 and 11 are readable.

예제1

  1. 예제 1

    입력
    3 3
    10
    7
    1
    0
    15
    2
    
    예상 출력
    10
    18
    11