AT_abc476_g.Increasing Popcount

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given positive integers LL and RR satisfying L≤RL\le R.

A sequence of positive integers A=(AL,AL+1,…,AR)A=(A_L,A_{L+1},\ldots,A_R) of length R−L+1R-L+1 satisfying the following condition is called a good integer sequence:

  • For every pair of integers (i,j)(i,j) satisfying L≤i<j≤RL\le i < j\le R, if Ai=AjA_i = A_j, then popcount⁡(i)<popcount⁡(j)\operatorname{popcount}(i)<\operatorname{popcount}(j).

Find the minimum value of max⁡(AL,AL+1,…,AR)\max(A_L,A_{L+1},\ldots,A_R) over all good integer sequences A=(AL,AL+1,…,AR)A=(A_L,A_{L+1},\ldots,A_R).

You are given TT test cases; solve each of them.

What is popcount⁡\operatorname{popcount}?

For a non-negative integer xx, popcount⁡(x)\operatorname{popcount}(x) is the number of 11's when xx is written in binary. More precisely, when a non-negative integer xx satisfies x=∑i=0∞bi2i (bi∈{0,1})\displaystyle x=\sum _ {i=0} ^ \infty b _ i2 ^ i\ (b _ i\in\lbrace0,1\rbrace), popcount⁡(x)=∑i=0∞bi\displaystyle\operatorname{popcount}(x)=\sum _ {i=0} ^ \infty b _ i.

For example, 1313 written in binary is 1101, so popcount⁡(13)=3\operatorname{popcount}(13)=3.

给定满足 L≤RL\le R 的正整数 LL 和 RR。

长度为 R−L+1R-L+1 的正整数序列 A=(AL,AL+1,…,AR)A=(A_L,A_{L+1},\ldots,A_R),若满足如下条件,则称为好整数序列:

  • 对于所有满足 L≤i<j≤RL\le i < j\le R 的整数对 (i,j)(i,j),若 Ai=AjA_i = A_j,则必有 popcount⁡(i)<popcount⁡(j)\operatorname{popcount}(i)<\operatorname{popcount}(j)。

求所有好整数序列 A=(AL,AL+1,…,AR)A=(A_L,A_{L+1},\ldots,A_R) 中 max⁡(AL,AL+1,…,AR)\max(A_L,A_{L+1},\ldots,A_R) 的最小可能值。

共给出 TT 组测试数据;请分别求解每组数据。

什么是 popcount⁡\operatorname{popcount}?

对于非负整数 xx,popcount⁡(x)\operatorname{popcount}(x) 表示 xx 的二进制表示中数字 11 的个数。更准确地说,当非负整数 xx 满足 x=∑i=0∞bi2i (bi∈{0,1})\displaystyle x=\sum _ {i=0} ^ \infty b _ i2 ^ i\ (b _ i\in\lbrace0,1\rbrace) 时,定义 popcount⁡(x)=∑i=0∞bi\displaystyle\operatorname{popcount}(x)=\sum _ {i=0} ^ \infty b _ i。

例如,1313 的二进制表示为 1101,因此 popcount⁡(13)=3\operatorname{popcount}(13)=3。

输入格式

The input is given from Standard Input in the following format:

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

Each test case is given in the following format.

LL RR

输入从标准输入中按以下格式给出:

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

每个测试用例按以下格式给出:

LL RR

输出格式

Output TT lines.

The ii-th line (1≤i≤T)(1\le i\le T) should contain the answer for the ii-th test case casei\text{case}_i.

输出 TT 行。

第 ii 行(1≤i≤T1\le i\le T)应包含第 ii 个测试用例 casei\text{case}_i 的答案。

输入输出样例

  • 输入#1

    5
    3 6
    1 1
    2 15
    100 10000000
    514284786278117031 620546740167642909

    输出#1

    3
    1
    6
    1636985
    11375123021856567

说明/提示

Sample 1 Explanation:
Consider the first test case.

(A3,A4,A5,A6)=(1,2,2,3)(A_3,A_4,A_5,A_6)=(1,2,2,3) is a good integer sequence, and max⁡(A3,A4,A5,A6)=3\max(A_3,A_4,A_5,A_6)=3.

There is no good integer sequence with max⁡(A3,A4,A5,A6)<3\max(A_3,A_4,A_5,A_6) < 3, so output 33 on the first line.

Constraints

  • 1≤T≤1041\le T\le 10^4
  • 1≤L≤R≤10181\le L \le R\le 10^{18}
  • All input values are integers.

样例 1 解释:
考虑第一个测试用例。

(A3,A4,A5,A6)=(1,2,2,3)(A_3,A_4,A_5,A_6)=(1,2,2,3) 是一个“好”的整数序列,且 max⁡(A3,A4,A5,A6)=3\max(A_3,A_4,A_5,A_6)=3。

不存在满足 max⁡(A3,A4,A5,A6)<3\max(A_3,A_4,A_5,A_6) < 3 的“好”整数序列,因此第一行输出 33。

约束条件

  • 1≤T≤1041\le T\le 10^4
  • 1≤L≤R≤10181\le L \le R\le 10^{18}
  • 所有输入值均为整数。

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

首页