分析:
icpccamp上是用数位dp做的,我个人感觉不需要吧。。
我是贪心做的。
因为
x|y>=max(x,y)
,所以我规定两个数
x,y,(x<=y)
,那么就让
y
取
代码:
/*****************************************************/
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <map>
#include <set>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define offcin ios::sync_with_stdio(false)
#define sigma_size 26
#define lson l,m,v<<1
#define rson m+1,r,v<<1|1
#define slch v<<1
#define srch v<<1|1
#define sgetmid int m = (l+r)>>1
#define ll long long
#define ull unsigned long long
#define mem(x,v) memset(x,v,sizeof(x))
#define lowbit(x) (x&-x)
#define bits(a) __builtin_popcount(a)
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const int INF = 0x3f3f3f3f;
const ll INFF = 1e18;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-9;
const ll mod = 1e9+7;
const int maxmat = 10;
const ull BASE = 133333331;
/*****************************************************/
inline void RI(int &x) {
char c;
while((c=getchar())<'0' || c>'9');
x=c-'0';
while((c=getchar())>='0' && c<='9') x=(x<<3)+(x<<1)+c-'0';
}
/*****************************************************/
ll x;
void work(ll l, ll r) {
for (int i = 62; i >= 0; i --) {
// cout<<x<<" "<<i<<endl;
int c = (r >> i) & 1;
if (c) {
ll tmp = x + (1ll << i) - 1;
if (tmp < l) x |= (1ll << i);
}
else {
ll tmp = x | (1ll << i);
if (tmp <= r) x |= (1ll << i);
}
}
}
int main(int argc, char const *argv[]) {
ll l, r;
int T; cin>>T;
while (T --) {
scanf("%I64d%I64d", &l, &r);
x = 0;
work(l, r);
printf("%I64d\n", x | r);
}
return 0;
}