Under construction

Still being built. Things may change

Intercastellar

Time limit2sMemory limit512 MB

Summary
Each even piece is repeatedly halved, always choosing the rightmost even piece, and queries ask for the final length at given positions from the left.
Level

Medium6 of 10

Topics
Simulation, Implementation, Binary search, Math
Solved
No attempts yet

Problem

In 30XX, thanks to the constant efforts of scientists and engineers, interaction among different planets has become very active. Bitaro is a beaver who works as an ambassador of an exchange program. His task is to introduce foods from the Earth to the inhabitants of different planets. He will leave for the JOI Planet at 1:00 in the afternoon.

Bitaro is planning to introduce castella to the inhabitants of the JOI Planet. The castella was already cut into several pieces. Castella is a baked sponge cake made of flour, egg, sugar, and starch syrup.

The shape of the castella is a horizontally long rectangular box. It was cut into NN pieces. The length of the ii-th piece (1≤i≤N1 ≤ i ≤ N) from the left is an integer A_iA\_i.

A couple of minutes ago, it turned out that the inhabitants of the JOI Planet do not like even integers. To cope with this problem, you will perform the following sequential operations until pieces of even length disappear.

  1. Among the pieces of even length, you choose the rightmost one.
  2. You cut the chosen piece into two pieces of equal length. Namely, if the length of the chosen piece is kk, you cut it into two pieces of length k2\frac{k}{2}. You do not move the position of the pieces.

To confirm whether the operations are performed correctly, Bitaro will ask you QQ questions. The jj-th question (1≤j≤Q1 ≤ j ≤ Q) is as follows.

  • After all the operations are performed, what is the length of the X_jX\_j-th piece from the left?

Given information of the castella and the questions, write a program which answers the questions.

Input

Read the following data from the standard input. Given values are all integers.

\begin{align\*} & N \\ & A\_1 \\ & A\_2 \\ & \vdots \\ & A\_N \\ & Q \\ & X\_1 \\ & X\_2 \\ & \vdots \\ & X\_Q\end{align\*}

Output

Write QQ lines to the standard output. The jj-th line (1≤j≤Q1 ≤ j ≤ Q) should contain the answer to the jj-th question.

Constraints

  • 1≤N≤200 0001 ≤ N ≤ 200\,000.
  • 1≤A_i≤1 000 000 0001 ≤ A\_i ≤ 1\,000\,000\,000 (1≤i≤N1 ≤ i ≤ N).
  • 1≤Q≤200 0001 ≤ Q ≤ 200\,000.
  • 1≤X_j≤1 000 000 000 000 0001 ≤ X\_j ≤ 1\,000\,000\,000\,000\,000 (=1015= 10^{15}) (1≤j≤Q1 ≤ j ≤ Q).
  • X_j≤X_j+1X\_j ≤ X\_{j+1} (1≤j≤Q−11 ≤ j ≤ Q - 1).
  • After all the operations are performed, the castella is cut into at least X_QX\_Q pieces.

Examples3

  1. Example 1

    Input
    4
    14
    9
    8
    12
    6
    2
    3
    5
    7
    11
    13
    
    Expected output
    7
    9
    1
    1
    1
    3
    
  2. Example 2

    Input
    13
    1
    4
    1
    4
    2
    1
    3
    5
    6
    2
    3
    7
    3
    8
    2
    10
    11
    13
    15
    17
    18
    20
    
    Expected output
    1
    1
    1
    1
    5
    3
    1
    3
    
  3. Example 3

    Input
    16
    536870912
    402653184
    536870912
    536870912
    134217728
    536870912
    671088640
    536870912
    536870912
    536870912
    939524096
    805306368
    536870912
    956301312
    536870912
    536870912
    5
    2500000000
    3355443201
    4294967296
    5111111111
    6190792704
    
    Expected output
    5
    1
    7
    57
    1