Problem F
Odd Rubble
Jinx is fantasizing about blowing things up again, when she comes across some neatly arranged piles of rubble. "What’d’ya say, Fishbones? Should we blow it up?"
Her rule is simple: if a rubble pile has even size, she’ll split it into two piles of half the size. She keeps doing this—recursively—until all piles have an odd size.
When a pile gets split into two, it doesn’t change its left-to-right position relative to other piles. For example, the piles 3 2 5 may become 3 1 1 5.
Jinx is still planning on how to explode all the rubble before "Piltover’s finest" can spoil the fun. While she does that, she wants you to figure out—looking at the new piles from left to right—what will the size of the $i$-th pile be?
Jinx has a lot of queries—and a lot of explosives—so you’d better answer quickly, just in case.
1 Input
The first line contains two integers $n$ and $q$ ($1 \leq n, q \leq 10^5$)—the number of initial rubble piles and the number of queries. The second line contains $n$ integers $a_1, a_2, \ldots , a_n$ ($1 \leq a_i \leq 10^{18}$)—the sizes of the rubble piles. Each of the next $q$ lines contains a single integer $x_i$ ($0 \leq x_i \leq 10^{18}$)—the index (0-based) of the pile to query after all explosions are complete.
The second line contains $n$ integers $a_1, a_2, \ldots , a_n$ ($1 \leq a_i \leq 10^{18}$) — the sizes of the rubble piles. It is guaranteed that $\sum _{i=1}^n a_i \leq 2 \cdot 10^{18}$.
Each of the next $q$ lines contains a single integer $x_i$ ($1 \leq x_i \leq 10^{18}$) — the (1-based) index of the pile to query after all explosions are complete.
Output
For each query, output a single line containing the size of the pile at index $x_i$ after all explosions. If the index is out of bounds, output $-1$.
Sample Input 1 | Sample Output 1 |
---|---|
5 5 2 3 6 3 8 8 7 4 6 10 |
1 1 3 3 1 |
Sample Input 2 | Sample Output 2 |
---|---|
1 1 4398046511104 2072689968062 |
1 |