Logo
(追記) (追記ここまで)

30743번 - A Leapfrog in the Array 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB544100.000%

문제

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:

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

입력

The first line contains two integers $n$ and $q$ (1ドル \leq n \leq 10^{18},ドル 1ドル \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 $q$ lines contain integers $x_i$ (1ドル \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 $q$ 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

예제 출력 1

3
2
4

힌트

출처

Olympiad > Moscow Open Olympiad in Informatics > Moscow Open Olympiad in Informatics 2017-18 > Day 2 Aivazovsky번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /