A Leapfrog in the Array

시간 제한2초메모리 제한1024 MB

요약
가장 오른쪽의 비어 있지 않은 칸에 든 수를 왼쪽의 가장 가까운 빈칸으로 옮기는 과정을 끝까지 수행했을 때, 각 질의 x번째 칸에 오는 수를 구한다.
난이도

어려움10점 중 8점

유형
수학, 재귀, 시뮬레이션
정답자
아직 제출이 없습니다

문제

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

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

입력

The first line contains two integers nn and qq (1≤n≤10181 \leq n \leq 10^{18}, 1≤q≤200,0001 \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 x_ix\_i (1≤x_i≤n1 \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

  1. 예제 1

    입력
    4 3
    2
    3
    4
    
    예상 출력
    3
    2
    4