Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
33801 A21μΘ_wjy 【S】T1 C++ 运行超时 60 1000 MS 264 KB 1348 2024-10-22 15:55:14

Tests(6/10):


//freopen #include<bits/stdc++.h> #define endl '\n' #define int long long #define PII pair<int,int> #define mp make_pair #define pb push_back #define fir first #define sec second using namespace std; int l,r; void slv(){ cin>>l>>r; if(l==r){ cout<<1<<endl; return; } vector<PII> v;v.clear(); v.pb(mp(l,r)); int FL=0,LIM=-1;bool cl=0; for(int x=60;x>=0;x--){ if(((l>>x)&1ll)==((r>>x)&1ll))if(!FL)continue; FL++; if(FL==1ll)LIM=x; else{ if(!((l>>x)&1ll)){ int LB=((l>>x)<<x)|(1ll<<x),RB=LB+(1ll<<x)-1ll; v.pb(mp(LB,RB)),v.pb(mp(LB+(1ll<<LIM),RB+(1ll<<LIM))); } if((r>>x)&1ll){ if(!cl){ int c=(r>>LIM)<<LIM; v.pb(mp(c,c+(1ll<<(x+1))-1ll));cl=1; } } } }if(LIM!=-1)v.pb(mp(l+(1ll<<LIM),l+(1ll<<LIM))); sort(v.begin(),v.end()); int ans=0,lst=-1; for(PII R:v){ if(lst<R.fir)ans+=R.sec-R.fir+1,lst=R.sec; else if(R.sec>lst)ans+=R.sec-lst,lst=R.sec; }cout<<ans<<endl; return; } signed main(){ // freopen("or.in","r",stdin); // freopen("or.out","w",stdout); int T; cin>>T; while(T--)slv(); cout.flush(); }


测评信息: