emmmm一开始还以为是道挺难的题。。其实模拟一下很容易发现规律。。

对空位i(i为偶数)进行讨论,那么如果下一个填的空位就是i的话,i之后的数列一定都被填满了,所以可以算出i之后有多少个数。。减去前面的数即i/2个,后面就剩下n-i/2了。。然后下一个填上来的肯定是位于数列最后一个,把当前位置加上去就得填充的是位于n+i/2的数了。。然后再看看n+i/2的数又是谁填充上去的就好了,直接递归。。

当然如果是奇数位数肯定是一开始就填好的那个辣。。

所以总结出答案为

f(x)=(x+1)/2   x为奇数

     =f(n+x/2)  x为偶数

然后貌似因为这题队友都上分了(窝为什么就没去打蛙qaq。。。

最后还是要说。。不管题会不会做。。先模拟一下再说。。。






/**
*        ┏┓    ┏┓
*        ┏┛┗━━━━━━━┛┗━━━┓
*        ┃       ┃  
*        ┃   ━    ┃
*        ┃ >   < ┃
*        ┃       ┃
*        ┃... ⌒ ...  ┃
*        ┃       ┃
*        ┗━┓   ┏━┛
*          ┃   ┃ Code is far away from bug with the animal protecting          
*          ┃   ┃ 神兽保佑,代码无bug
*          ┃   ┃           
*          ┃   ┃       
*          ┃   ┃
*          ┃   ┃           
*          ┃   ┗━━━┓
*          ┃       ┣┓
*          ┃       ┏┛
*          ┗┓┓┏━┳┓┏┛
*           ┃┫┫ ┃┫┫
*           ┗┻┛ ┗┻┛
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-12
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 200005
#define nm 7000000
#define pi 3.1415926535897931
using namespace std;
const ll inf=1000000;
ll read(){
ll x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f*x;
}



ll n,m;
ll f(ll x){return x%2?(x+1)/2:f(n+x/2);}
int main(){
n=read();m=read();
while(m--)printf("%I64d\n",f(read()));
return 0;
}







D. A Leapfrog in the Array



time limit per test



memory limit per test



input



output



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 2i - 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:



cf950D(数学)_#include


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 ≤ 1018, 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 xi (1 ≤ xi ≤ n), the indices of cells for which it is necessary to output their content after Dima's algorithm finishes.



Output



For each of q



Examples



Copy



4 3 2 3 4



Output



3 2 4



Copy



13 4 10 5 4 8



Output



13 3 8 9



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].