QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#145389#6655. 巧克力qzez#AC ✓1126ms3956kbC++141.6kb2023-08-22 10:32:352023-08-22 10:32:36

Judging History

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

  • [2023-08-22 10:32:36]
  • 评测
  • 测评结果:AC
  • 用时:1126ms
  • 内存:3956kb
  • [2023-08-22 10:32:35]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=60+5,M=N*4+5,K=31650,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
ll n,m,k,p;
ll dp[N][2][2][2],tg[N][2][2][2];
ll dfs(int x,int y,int o1,int o2){
	if(x<0) return o1&&o2&&!y;
	if(tg[x][y][o1][o2]) return dp[x][y][o1][o2];
	ll &ans=dp[x][y][o1][o2];tg[x][y][o1][o2]=1;
	for(int i=0;i<8;i++)if(!((i&1)^(i>>1&1)^(i>>2&1)^(p>>x&1))){
		if((i&1)>(k>>x&1)&&!o1) continue;
		for(int j=0;j<2;j++){
			if((i>>1&1)+(i>>2&1)+j<2*y||(i>>1&1)+(i>>2&1)+j>2*y+1) continue;
			if((i>>1&1)+(i>>2&1)+j>2*y+(i&1)&&!o2) continue;
			ans+=dfs(x-1,j,o1|((i&1)<(k>>x&1)),o2|((i>>1&1)+(i>>2&1)+j<2*y+(i&1)));
		}
	}
	// cerr<<k<<' '<<x<<' '<<y<<' '<<o1<<' '<<o2<<' '<<ans<<'\n';
	return ans%=mod;
}
ll calc(ll m){
	Me(dp,0);Me(tg,0);k=m+1;
	return dfs(60,0,0,0);
}
void Solve(){
	int i,j;scanf("%lld%lld",&n,&m);
	p=m;
	if(n%4==0) p^=n;
	else if(n%4==1) p^=n^(n-1);
	else if(n%4==2) p^=n^(n-1)^(n-2);
	if(!p) {puts("0");return;}
	// cerr<<p<<'\n';
	// cerr<<calc(4)<<'\n';
	printf("%lld\n",(calc(n)+calc(m)-calc(m-1)+mod)%mod);
}
int main(){
	int t;
	scanf("%d",&t);
	// t=1;
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1126ms
memory: 3956kb

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