A Leapfrog in the Array | 프로그래밍의 벗 PivotOJ
PivotOJ

A Leapfrog in the Array

시간 제한: 2000ms메모리 제한: 1024MB출처: MOOI 2017-18 finalBOJ 30743
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

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 nn numbers from 11 to nn and the number ii is located in the cell with the index 2i12i - 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 nn numbers will appear in the first nn cells of the array. For example if n=4n = 4, the array is changing as follows:

[이미지 1]

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

입력

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

Next qq lines contain integers xix_i (1xin1 \leq x_i \leq n), the indices of cells for which it is necessary to output their content after Dima's algorithm finishes.

출력

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

예제

예제 1

입력
4 3
2
3
4
출력
3
2
4
코드를 제출하려면 로그인하세요.