Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
33771 LYLAKIOI 【S】T1 C++ 通过 100 222 MS 264 KB 1660 2024-10-22 15:07:26

Tests(10/10):


#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define pi pair<int,int> #define p1 first #define p2 second #define m_p make_pair #define p_b push_back using namespace std; typedef long long ll; inline ll read(){ ll x=0;short t=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; } void slv(){ ll L=read(),R=read(); if(L==R){ printf("1\n");return; } vector<pair<ll,ll> >vec; vec.p_b(m_p(L,R)); int flg=0;ll p=-1;int ok=0; down(i,60,0){ ll x=i; if(((L>>x)&1)==((R>>x)&1)){ if(!flg)continue; }flg++; if(flg==1)p=i; //cout<<"! "<<x<<" "<<flg<<endl; if(flg>=2){ if(!((L>>x)&1)){ ll w=(L>>x)<<x; w|=(1ll<<x); vec.p_b(m_p(w,w+(1ll<<x)-1)); vec.p_b(m_p(w+(1ll<<p),w+(1ll<<x)-1+(1ll<<p))); } if((R>>x)&1){ if(!ok){ ll S=(R>>p)<<p; vec.p_b(m_p(S,S+(1ll<<(x+1))-1)); ok=1; } } } }if(p!=-1)vec.p_b(m_p(L+(1ll<<p),L+(1ll<<p))); sort(vec.begin(),vec.end()); ll res=0,lst=-1; for(auto it:vec){ if(lst<it.p1)res+=it.p2-it.p1+1,lst=it.p2; else if(it.p2>lst)res+=it.p2-lst,lst=it.p2; }printf("%lld\n",res); }int main(){ int t=read();while(t--)slv(); fclose(stdin); fclose(stdout); return 0; }


测评信息: