QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#400822#4900. 数列重排2020zym20 65ms16616kbC++141.9kb2024-04-27 16:38:382024-04-27 16:38:38

Judging History

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

  • [2024-04-27 16:38:38]
  • 评测
  • 测评结果:20
  • 用时:65ms
  • 内存:16616kb
  • [2024-04-27 16:38:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int MOD=998244353;
char s[10000010];
long long Ans[10000111],n;
int zan[10000010],cun[10000010],m,l,r,x,buf[10000010],ji1[10000011];
void dfs(int x){
	if(x>n){
		for(int i=0;i<=m;i++)ji1[i]=0;
		for(int i=1;i<=n;i++){
			int op=0;
			for(int j=0;j<=m-1;j++)buf[j]=0;
			for(int j=i;j<=n;j++){
				buf[zan[j]]=1;
				while(buf[op])op++;
				ji1[op]++;
			}
		}
		for(int i=m-1;i>=0;i--)ji1[i]+=ji1[i+1];
		for(int i=0;i<=m;i++)Ans[i]=max(Ans[i],(long long)ji1[i]);
		return;
	}
	for(int i=0;i<=m-1;i++){
		if(cun[i]){
			zan[x]=i;
			cun[i]--;
			dfs(x+1);
			cun[i]++;
			zan[x]=0;
		}
	}
}
long long ksm(long long x,long long y){
	long long ans=1;
	while(y){
		if(y&1)ans=ans*x%MOD;
		x=x*x%MOD,y>>=1;
	}
	return ans;
}
int main(){
	scanf("%d%d%d%d",&m,&l,&r,&x);
	scanf("%s",s);
	for(int i=0;i<=m-1;i++)cun[i]=x+(s[i]=='1'),n+=cun[i];
	if(n<=9){	
		dfs(1);
		int op=1;
		long long ans=0;
		for(int i=0;i<=r;i++){
			if(i>=l)ans^=(op*1ll*Ans[i]%MOD);
			op=op*233ll%MOD;
		}
		printf("%lld\n",ans);	
	}
	else{
		if(l==m&&r==m){
			int minn=0x3f3f3f3f;
			for(int i=0;i<=m-1;i++)minn=min(minn,cun[i]);
			int l1=0,l2=0;
			for(int i=0;i<=m-1;i++){
				if(cun[i]==minn)break;
				l1++;
			}
			for(int i=m-1;i>=0;i--){
				if(cun[i]==minn)break;
				l2++;
			}
			printf("%lld\n",(minn*1ll*m+l1+l2-m+1)*ksm(233,m)%MOD);
			return 0;
		}
		if(m<=2&&l==0&&r==1){
			Ans[1]=(n*1ll*(n+1)/2-cun[1])%MOD;
			Ans[0]=(n*1ll*(n+1)/2)%MOD;
			printf("%lld\n",(Ans[0])^(Ans[1]*233%MOD));
			return 0;
		}
		if(x==1){
			Ans[0]=(n*1ll*(n+1)/2)%MOD;
			for(int i=1;i<=m;i++){
				long long op=m-i,op2=op/2;
				Ans[i]=(op2+1)*(op-op2+1)%MOD;
			}
			long long op=1;
			long long ans=0;
			for(int i=0;i<=r;i++){
				if(i>=l)ans^=(op*1ll*Ans[i]%MOD);
				op=op*233ll%MOD;
			}
			printf("%lld\n",ans);
			return 0;	
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 1ms
memory: 3788kb

input:

2 0 2 2
01

output:

541257

result:

ok 1 number(s): "541257"

Test #2:

score: 5
Accepted
time: 1ms
memory: 3784kb

input:

4 1 4 2
00001

output:

525797597

result:

ok 1 number(s): "525797597"

Test #3:

score: 5
Accepted
time: 65ms
memory: 3868kb

input:

9 0 9 1
000000000

output:

711136343

result:

ok 1 number(s): "711136343"

Test #4:

score: 5
Accepted
time: 1ms
memory: 3796kb

input:

1 0 1 9
0

output:

10456

result:

ok 1 number(s): "10456"

Test #5:

score: 5
Accepted
time: 0ms
memory: 3788kb

input:

2 1 2 3
11


output:

1518844

result:

ok 1 number(s): "1518844"

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #6:

score: 0
Wrong Answer
time: 1ms
memory: 3832kb

input:

21 0 21 9
111010011100100100000

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 5
Accepted

Test #14:

score: 5
Accepted
time: 0ms
memory: 3920kb

input:

2 0 1 114514
10

output:

934764137

result:

ok 1 number(s): "934764137"

Test #15:

score: 5
Accepted
time: 0ms
memory: 3908kb

input:

2 0 1 1919810
01

output:

685371514

result:

ok 1 number(s): "685371514"

Test #16:

score: 5
Accepted
time: 0ms
memory: 3928kb

input:

2 0 1 500000000
00

output:

318651831

result:

ok 1 number(s): "318651831"

Subtask #5:

score: 0
Wrong Answer

Test #17:

score: 0
Wrong Answer
time: 3ms
memory: 8780kb

input:

1000000 1000000 1000000 928
01100010010000000101111110001111011101111000011110100101011110011001001000011000110101101100111110000100101010111001111100010011100110000000111110110100001100000000011101100001010001010000010000001001000110011111010101111100001001110110010100000011000010010001111010011100...

output:

285149273

result:

wrong answer 1st numbers differ - expected: '437299311', found: '285149273'

Subtask #6:

score: 10
Accepted

Test #19:

score: 10
Accepted
time: 7ms
memory: 16612kb

input:

1000000 0 1000000 1
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

852768823

result:

ok 1 number(s): "852768823"

Test #20:

score: 10
Accepted
time: 7ms
memory: 16616kb

input:

1000000 0 1000000 1
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

852768823

result:

ok 1 number(s): "852768823"

Subtask #7:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 0ms
memory: 8464kb

input:

1000000 0 9823 627
01110001011101001100010011100101001011000011011110001101010000000101010111110111110010010001110100101001111000111100011101111001000000100111000010010100010101110110111110100010101010001110111001100011010001111000101010000110010010101110101010111110110001110111111000001110000110011...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Subtask #8:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%

Subtask #9:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%