#P8160. Castella Splitting

    ID: 21342 Type: Default 1000ms 256MiB

Castella Splitting

Castella Splitting

We are given a castella, i.e., a long horizontal rectangular bar, which is initially cut into (N) segments. The (i)-th segment from the left has an integer length (A_i).

Recently, we learned that the residents of JOI planet dislike even numbers. To resolve this, you will repeatedly perform the following operation until no segment of even length exists:

  1. Among all segments with an even length, choose the rightmost one.
  2. If the chosen segment has length \(k\), split it into two equal segments, each of length \(\frac{k}{2}\).

After all operations have been performed, each original segment \(A_i\) will have been transformed as follows. Express \(A_i\) as \(A_i = r \times 2^e\), where \(r\) is odd. Then the segment will eventually become \(2^e\) segments, each of length \(r\).

You are asked \(Q\) queries. In the \(j\)-th query, report the length of the \(X_j\)-th segment from the left after performing all operations.

inputFormat

The input is given in the following format:

N Q
A1 A2 ... AN
X1
X2
... 
XQ

Here, \(N\) is the number of segments and \(Q\) is the number of queries. The second line contains \(N\) integers \(A_1, A_2, \dots, A_N\) representing the lengths of the segments. Each of the next \(Q\) lines contains a single integer \(X_j\), the 1-indexed position of the segment to query in the final configuration.

outputFormat

For each query, output a single line containing the length of the corresponding segment after all the operations have been performed.

sample

3 3
3 8 6
1
5
9
3

1 1

</p>