agc015d
题目
思路:
首先可以把L,R中二进制相同的前几位去掉,然后此时L的第一位是0,R的第一位是1
这样就可以分两类讨论:
第一类:
x=1000000 // 只保留最高位的 1
y=0111111 // x-1
这样我们可以得到[x|A,M]内的所有数
第二类:
p=1001000 // 保留最高位和次高位的 1
q=1000111 // p-1
这样我们可以得到[B+1,p|q]内的所有数
然后就做完了
这道题主要是分类讨论比较难想,其他倒还好
#include<bits/stdc++.h>
using namespace std;
struct FIO{static const int BUF_SIZE=1<<19;char _i[BUF_SIZE],*_1=_i,*_2=_i,_o[BUF_SIZE],*_t=_o;inline char _gt(){if(_1==_2){_1=_i;_2=_i+fread(_i,1,BUF_SIZE,stdin);}return _1==_2?EOF:*_1++;}inline void _pt(char c){if(_t-_o==BUF_SIZE){fwrite(_o,1,BUF_SIZE,stdout);_t=_o;}*_t++=c;}int _pr=6,le,_ob[20];template<typename T>FIO&operator>>(T&x){x=0;char c=_gt();bool sg=false;while(c!=EOF&&(c<'0'||c>'9')){if(c=='-')sg=true;c=_gt();}while(c!=EOF&&c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=_gt();}if(sg)x=-x;return*this;}FIO&operator>>(char*s){char c=_gt();while(c!=EOF&&c<33)c=_gt();while(c!=EOF&&c>=33)*s++=c,c=_gt();*s='\0';return*this;}FIO&operator>>(string&s){s.clear();char c=_gt();while(c!=EOF&&c<33)c=_gt();while(c!=EOF&&c>=33)s+=c,c=_gt();return*this;}FIO&operator>>(char&x){char c=_gt();while(c!=EOF&&c<33)c=_gt();x=c;return*this;}FIO&operator>>(double&x){x=0;char c=_gt();bool sg=0;while(c!=EOF&&c<33)c=_gt();if(c=='-'){sg=1;c=_gt();}while(c!=EOF&&c>='0'&&c<='9'){x=x*10+(c^48);c=_gt();}if(c=='.'){c=_gt();double tp=0.1;while(c!=EOF&&c>='0'&&c<='9'){x+=(c^48)*tp;tp*=0.1;c=_gt();}}if(sg)x=-x;return*this;}FIO&setprecision(int n){_pr=n<0?0:n;return*this;}template<typename T>FIO&operator<<(T x){if(x<0){_pt('-');x=-x;}if(x==0){_pt('0');return*this;}char _b[20];int ps=0;while(x>0){_b[ps++]=(x%10)^48;x/=10;}while(ps>0)_pt(_b[--ps]);return*this;}FIO&operator<<(const char*s){while(*s)_pt(*s++);return*this;}FIO&operator<<(const string&s){for(char c:s)_pt(c);return*this;}FIO&operator<<(char c){_pt(c);return*this;}FIO&operator<<(double x){if(x<0)_pt('-'),x=-x;if(isnan(x))return _pt('n'),_pt('a'),_pt('n'),*this;if(isinf(x))return _pt('i'),_pt('n'),_pt('f'),*this;long long ip=(long long)x;x-=ip;if(_pr==0){x*=10;if(x>=5)ip++;return*this<<ip;}le=0;_ob[0]=0;for(int i=1;i<=_pr;i++){x*=10;_ob[++le]=(int)x;x-=(int)x;}x*=10;int _tp=(int)x;if(_tp>=5){int j=le;_ob[le]++;while(_ob[j]==10)_ob[j-1]++,_ob[j]=0,j--;}ip+=_ob[0];*this<<ip<<".";for(int i=1;i<=le;i++)*this<<_ob[i];return*this;}~FIO(){fwrite(_o,1,_t-_o,stdout);}}fst;
#define cin fst
#define cout fst
#define il inline
typedef long long ll;
int main(){
ll a,b;
cin>>a>>b;
if(a==b)return cout<<1,0;
ll t=(1ll<<__lg(a^b));
a&=(t-1); b&=(t-1);
cout<<min(b>0?(2ll<<__lg(b)):1ll,a)+((t-a)<<1);
return 0;
}

浙公网安备 33010602011771号