CF484A.Bits

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer x.

You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and is maximum possible. If there are multiple such numbers find the smallest of them.

我们用 表示非负整数 xx 的二进制表示中置位(即值为 '1')的比特位个数。

你将收到多个查询,每个查询由一对整数 ll 和 rr 组成。对每个查询,请找出满足 l≤x≤rl \le x \le r 且 尽可能大的整数 xx。若存在多个满足条件的数,则输出其中最小的一个。

输入格式

The first line contains integer n — the number of queries (1 ≤ n ≤ 10000).

Each of the following n lines contain two integers l__i, r__i — the arguments for the corresponding query (0 ≤ l__i ≤ r__i ≤ 1018).

第一行包含一个整数 nn — 查询的数量(1 ≤ n ≤ 100001 \leq n \leq 10000)。

接下来的 nn 行,每行包含两个整数 lil_i、rir_i — 对应查询的参数(0 ≤ li ≤ ri ≤ 10180 \leq l_i \leq r_i \leq 10^{18})。

输出格式

For each query print the answer in a separate line.

对于每个查询,在单独的一行中输出答案。

输入输出样例

  • 输入#1

    3
    1 2
    2 4
    1 10

    输出#1

    1
    3
    7

说明/提示

The binary representations of numbers from 1 to 10 are listed below:

110 = 12

210 = 102

310 = 112

410 = 1002

510 = 1012

610 = 1102

710 = 1112

810 = 10002

910 = 10012

1010 = 10102

1 到 10 的数字的二进制表示如下所示:

110=121_{10} = 1_2

210=1022_{10} = 10_2

310=1123_{10} = 11_2

410=10024_{10} = 100_2

510=10125_{10} = 101_2

610=11026_{10} = 110_2

710=11127_{10} = 111_2

810=100028_{10} = 1000_2

910=100129_{10} = 1001_2

1010=1010210_{10} = 1010_2

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

首页