QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#625174#9346. Binary Numbersucup-team4352#WA 10ms8064kbC++231.2kb2024-10-09 17:45:442024-10-09 17:45:44

Judging History

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

  • [2024-10-09 17:45:44]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:8064kb
  • [2024-10-09 17:45:44]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define lowbit(x) (x&-x)
#define log(x) (31^__builtin_clz(x))
using namespace std;
const int p=1e9+7;
int l[1000005],r[1000005];
int s[1000005];
inline int calc(int x,int y){
	int tmp=x^y;
	for(int i=20;i>=0;i--){
		if(tmp>>i&1)return 20-i;
	}
	return 21;
}
void solve(){
	int m,n;
	cin>>m>>n;
	for(int i=1;i<=n;i++){
		cin>>l[i]>>r[i];
	}
	for(int i=0;i<(1<<m);i++)s[i]=0;
	for(int i=l[1];i<=r[1];i++){
		s[i]=i+s[i-1];
		if(s[i]>=p)s[i]-=p;
	}
	for(int i=2;i<=n;i++){
		int nowl=l[i]-1,nowr=l[i]-1;
		for(int j=l[i];j<=r[i];j++){
			while(nowl>l[i-1]&&calc(nowl-1,r[i-1])>=calc(j,r[i-1]))nowl--;
			while(nowr>=nowl&&calc(nowr-1,l[i])>calc(j,l[i]))nowr--;
			if(nowl>nowr)continue;
			s[j]=s[nowr];
			if(nowl>l[i-1])s[j]-=s[nowl-1];
			if(s[j]<0)s[j]+=p;
		}
		s[l[i]]=1ll*s[l[i]]*l[i]%p;
		for(int j=l[i]+1;j<=r[i];j++){
			s[j]=(1ll*s[j]*j+s[j-1])%p;
		}
	}
	// for(int i=0;i<(1<<m);i++)cout<<s[i]<<"\n";
	cout<<s[(1<<m)-1]<<"\n";
}
int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t=1;
	cin>>t;
	while(t--)solve();
	return 0;
}
/*
1
 3 3
 0 1
 2 3
 4 7
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7744kb

input:

1
2 2
0 1
2 3

output:

5

result:

ok single line: '5'

Test #2:

score: -100
Wrong Answer
time: 10ms
memory: 8064kb

input:

20
4 6
0 1
2 3
4 6
7 7
8 11
12 15
9 39
0 31
32 47
48 51
52 63
64 87
88 92
93 95
96 127
128 143
144 159
160 167
168 175
176 191
192 207
208 255
256 263
264 271
272 283
284 287
288 289
290 295
296 303
304 319
320 351
352 357
358 367
368 375
376 383
384 391
392 399
400 403
404 407
408 415
416 443
444 4...

output:

430920
630134526
132694531
496341250
807025817
5040
28188720
440292990
955103286
411662851
51712424
634845771
2268
147499198
1
926578985
398150840
662615184
28
442551630

result:

wrong answer 2nd lines differ - expected: '27651757', found: '630134526'