QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#275345#6655. 巧克力rageOfThunder#AC ✓1287ms3540kbC++142.5kb2023-12-04 17:05:332023-12-04 17:05:34

Judging History

你现在查看的是最新测评结果

  • [2023-12-04 17:05:34]
  • 评测
  • 测评结果:AC
  • 用时:1287ms
  • 内存:3540kb
  • [2023-12-04 17:05:33]
  • 提交

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