#P4868. Bits

    ID: 2506 传统题 1000ms 256MiB 尝试: 1 已通过: 1 难度: 10 上传者: 标签>基础算法贪心位运算数论进制CodeForces

Bits

Bits

题面翻译

- $n$组询问,每次给出一个区间$l, r$,你需要输出在这个区间内二进制表示中1的个数最多的数

- 如有多个答案,输出最小的那个

- $(n \leq10^4, 0\leq l, r \leq10^{18})$

效果

  • nn组询问,每次给出一个区间l,rl, r,你需要输出在这个区间内二进制表示中1的个数最多的数

  • 如有多个答案,输出最小的那个

  • (n104,0l,r1018)(n \leq10^4, 0\leq l, r \leq10^{18})

题目描述

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

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

输入格式

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

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

输出格式

For each query print the answer in a separate line.

样例 #1

样例输入 #1

3
1 2
2 4
1 10

样例输出 #1

1
3
7

提示

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

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