CF949B.A Leapfrog in the Array

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 ≤ x ≤ n) after Dima's algorithm finishes.

迪马是一名初学编程者。在日常编程过程中,他需要反复执行如下操作:从数组中删除所有位于偶数位置的元素。某天,他对这个问题的简单解法感到厌倦,于是提出了一种别出心裁的算法。

假设初始时,数组包含从 11 到 nn 的 nn 个数,且数字 ii 位于下标为 2i−12i-1 的单元格中(下标从 11 开始编号),而数组其余单元格为空。每一步,迪马选择当前所有非空单元格中下标最大的一个,并将其中的数字移动到该单元格左侧最近的一个空单元格中。该过程持续进行,直到全部 nn 个数字都出现在数组的前 nn 个单元格中为止。例如,当 n=4n = 4 时,数组的变化过程如下所示:

你需要编写一个程序,用于确定在迪马的算法执行完毕后,下标为 xx(1≤x≤n1 \le x \le n)的单元格中所存放的数字是多少。

输入格式

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

第一行包含两个整数 nn 和 qq(1≤n≤10181 \leq n \leq 10^{18},1≤q≤200 0001 \leq q \leq 200\,000),分别表示数组的元素个数以及需要回答查询的次数。

接下来 qq 行,每行包含一个整数 xix_i(1≤xi≤n1 \leq x_i \leq n),表示需要在 Dima 的算法执行完毕后输出其内容的单元格索引。

输出格式

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

对于每个查询,输出一个整数,即在迪马(Dima)算法执行完毕后,对应数组单元格中出现的值。

输入输出样例

  • 输入#1

    4 3
    2
    3
    4

    输出#1

    3
    2
    4
  • 输入#2

    13 4
    10
    5
    4
    8

    输出#2

    13
    3
    8
    9

说明/提示

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

第一个示例如图所示。

在第二个示例中,最终的数组为 [1, 12, 2, 8, 3, 11, 4, 9, 5, 13, 6, 10, 7]。

输入解题思路,AI测评打分。不知道怎么写?

首页