第一天的sum原来没a但是思路完全是对的,自己又优化了一下就a了
#include<iostream> #include<cstdio> #include<cstring> using namespace std; #define ll long long #define mod 23333333333333333ll ll pc(ll x,ll y) { x=x%mod,y=y%mod; ll ans=0; while(y) { if(y&1) ans=(ans+x)%mod; x=(x+x)%mod,y>>=1; } return ans; } ll suan(ll x,ll y,int w){ ll ans=0; if(x<0)return 0; if(x==0)return (y^0); if(x==1)return ((y^1)+(y^0))%mod; for(;w>0;w--){ ll i=(ll)1<<w; if(x&i){ ans=(ans+pc(i-1,i/2))%mod; if(y&i)ans=(ans+pc(i,i))%mod; y=y^i; x=x-i; ans=(ans+suan(x,y,w))%mod; break; } if(y&i){ ans=(ans+pc(x+1,i))%mod; y-=i; ans=(ans+suan(x,y,w))%mod; break; } } //cout<<ans<<endl; return ans; } int main(){ freopen("sum.in","r",stdin); freopen("sum.out","w",stdout); int t; cin>>t; ll a,b,c; while(t--){ cin>>a>>b>>c; ll ans=(suan(b,c,62)-suan(a-1,c,62)+mod)%mod; //cout<<suan(b,c,62)<<" "<<suan(a-1,c,62); cout<<ans<<endl; } return 0; }
思路跟gyk大佬完全一样(考试的时候),就是用到递归,一位一位往下砍。感觉还是自己写出来感觉比较好。