QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#275345 | #6655. 巧克力 | rageOfThunder# | AC ✓ | 1287ms | 3540kb | C++14 | 2.5kb | 2023-12-04 17:05:33 | 2023-12-04 17:05:34 |
Judging History
answer
//-DYUNQIAN -std=c++14 -O2 -Wall
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define fi first
#define se second
#define mk make_pair
using namespace std;
inline int read(){
int x=0,f=1;char c=getchar();
for(;(c<'0'||c>'9');c=getchar()){if(c=='-')f=-1;}
for(;(c>='0'&&c<='9');c=getchar())x=x*10+(c&15);
return x*f;
}
const int mod=1e9+7;
int ksm(int x,int y,int p=mod){
int ans=1;
for(int i=y;i;i>>=1,x=1ll*x*x%p)if(i&1)ans=1ll*ans*x%p;
return ans%p;
}
int inv(int x,int p=mod){return ksm(x,p-2,p)%p;}
mt19937 rnd(time(0));
int randint(int l,int r){return rnd()%(r-l+1)+l;}
void add(int &x,int v){x+=v;if(x>=mod)x-=mod;}
void Mod(int &x){if(x>=mod)x-=mod;}
void Assert(bool c,int L=0){if(!c){cout<<"Assertion Failed at "<<L<<endl;exit(0);}}
void cmax(int &x,int v){x=max(x,v);}
void cmin(int &x,int v){x=min(x,v);}
int f[2][4][3][2];
signed main(void){
#ifdef YUNQIAN
freopen("in.in","r",stdin);
#endif
auto F=[&](int n,int S){
if(n<=0)return 0ll;
memset(f,0,sizeof(f));
vector<int>vals,tv;
// cout<<"get "<<n<<endl;
while(n)vals.emplace_back(n%2),n/=2;
while(S)tv.emplace_back(S%2),S/=2;
if(tv.size()>vals.size())return 0ll;tv.resize(vals.size());
// cout<<"vals = ";for(int x:vals)cout<<x<<" ";puts("");
int cur=0;f[cur][0][1][0]=1;
for(int i=0;i<vals.size();i++){
memset(f[cur^1],0,sizeof(f[cur^1]));
for(int j=0;j<=3;j++)for(int k=0;k<=2;k++)for(int l=0;l<=1;l++)if(f[cur][j][k][l]){
// cout<<"f "<<i-1<<" "<<j<<" "<<k<<" "<<l<<" = "<<f[cur][j][k][l]<<endl;
for(int a=0;a<=1;a++)for(int b=0;b<=1;b++)for(int c=0;c<=1;c++)if(a^b^((a+b+c+j)%2)==tv[i]){
int tj=(j+a+b+c)/2;
int tk=k,v=(j+a+b+c)%2;
if(v==1&&vals[i]==0)tk=2;// >
if(v==0&&vals[i]==1)tk=0;// <
int tl=(l|(c==1));
add(f[cur^1][tj][tk][tl],f[cur][j][k][l]);
}
}
cur^=1;
}
// for(int j=0;j<=3;j++)for(int k=0;k<=2;k++)for(int l=0;l<=1;l++)if(f[cur][j][k][l])cout<<"f "<<vals.size()<<" "<<j<<" "<<k<<" "<<l<<" = "<<f[cur][j][k][l]<<endl;
int ans=0;
for(int j=0;j<=0;j++)for(int k=0;k<=1;k++)for(int l=1;l<=1;l++)add(ans,f[cur][j][k][l]);
return ans;
};
int tt=read();while(tt--){
int n=read(),m=read();
int S=m;
if(n%4==0)S^=n;
if(n%4==1)S^=n^(n-1);
if(n%4==2)S^=n^(n-1)^(n-2);
if(n%4==3)S^=n^(n-1)^(n-2)^(n-3);// = 0
// cout<<"S = "<<S<<endl;
cout<<((F(n,S)+F(m,S)-F(m-1,S))%mod+mod)%mod<<"\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1287ms
memory: 3540kb
input:
50000 0 0 0 1 0 2 0 3 0 4 0 5 1 0 1 1 1 2 1 3 1 4 1 5 2 0 2 1 2 2 2 3 2 4 2 5 3 0 3 1 3 2 3 3 3 4 3 5 4 0 4 1 4 2 4 3 4 4 4 5 5 0 5 1 5 2 5 3 5 4 5 5 0 2000000013 3 2000000013 960420868510113883 392659194919473988 668803384430801620 162045456939453012 617795168362576047 722239203838631701 6050650100...
output:
0 1 1 2 2 3 1 0 2 2 2 2 2 1 1 0 4 4 0 4 4 6 2 3 2 2 2 4 0 5 5 0 6 5 7 6 0 0 617401866 87835503 788974705 719403921 388746468 343575572 346563231 107105273 892988359 21085898 256773311 736064559 221068497 268198252 311484988 140174338 95593482 477651660 154447963 420109896 648989232 806537128 7685205...
result:
ok 50000 numbers