Codeforces Round 469 (Div. 1)
B
A Leapfrog in the Array
Codeforces
1700
原题
← AC →
翻译中…

Dima is a beginner programmer. During his working process, he regularly has to repeat the following operation again and again: to remove every second element from the array. One day he has been bored with easy solutions of this problem, and he has come up with the following extravagant algorithm.

翻译中…

Let's consider that initially array contains $*n*$ numbers from $1$ to $*n*$ and the number $*i*$ is located in the cell with the index $2*i* - 1$ (Indices are numbered starting from one) and other cells of the array are empty. Each step Dima selects a non-empty array cell with the maximum index and moves the number written in it to the nearest empty cell to the left of the selected one. The process continues until all $*n*$ numbers will appear in the first $*n*$ cells of the array. For example if $*n* = 4$, the array is changing as follows:

翻译中…

image

翻译中…

You have to write a program that allows you to determine what number will be in the cell with index $*x*$ ($1 ≤ *x* ≤ *n*$) after Dima's algorithm finishes.

翻译中…

Input

翻译中…

The first line contains two integers $*n*$ and $*q*$ ($1 ≤ *n* ≤ 10^{18}$, $1 ≤ *q* ≤ 200 000$), the number of elements in the array and the number of queries for which it is needed to find the answer.

翻译中…

Next $*q*$ lines contain integers $*x*_{*i*}$ ($1 ≤ *x*_{*i*} ≤ *n*$), the indices of cells for which it is necessary to output their content after Dima's algorithm finishes.

翻译中…

Output

翻译中…

For each of $*q*$ queries output one integer number, the value that will appear in the corresponding array cell after Dima's algorithm finishes.

翻译中…

Note

翻译中…

The first example is shown in the picture.

翻译中…

In the second example the final array is $[1, 12, 2, 8, 3, 11, 4, 9, 5, 13, 6, 10, 7]$.

翻译中…

样例

Input #1
4 3
2
3
4
Output #1
3
2
4
InputCopy OutputCopy
Input #2
13 4
10
5
4
8
Output #2
13
3
8
9
InputCopy OutputCopy
题目信息
题号
949B
时间限制
2 s
内存限制
512 MB
标签
构造
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。