QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#401015#4900. 数列重排QBF35 12ms22840kbC++143.6kb2024-04-27 20:54:252024-04-27 20:54:28

Judging History

This is the latest submission verdict.

  • [2024-04-27 20:54:28]
  • Judged
  • Verdict: 35
  • Time: 12ms
  • Memory: 22840kb
  • [2024-04-27 20:54:25]
  • Submitted

answer

#include<bits/stdc++.h>
#define ci const int
#define ll long long
using namespace std;
ci N=1e6+5,mod=998244353;
inline void add(int &x,ci v){
	x+=v,x-=x<mod?0:mod;
}
inline void sub(int &x,ci v){
	x-=v,x+=x<0?mod:0;
}
int n,m,l,r,x,cnt[N],a[N],sum[N],pre[N];
bool h[N];
ll ans[N];
void check(){
	for(int i=0;i<=m;++i)sum[i]=0;
	for(int i=1;i<=n;++i){
		for(int j=0;j<=m;++j)h[j]=0;
		for(int j=i,mx=0;j<=n;++j){
			h[a[j]]=1;
			while(h[mx])++mx;
			++sum[mx];
		}
	}
	for(int i=m;~i;--i)sum[i]+=sum[i+1],ans[i]=max(ans[i],(ll)sum[i]);
}
bool tp[N];
int calc(ci lim){
//	for(int i=1;i<=n;++i)printf("%d",(int)tp[i]);puts("");
	int ans=0;
	for(int i=1;i<=n;++i)
		for(int j=i,cnt=0;j<=n;++j)
			cnt+=tp[j],
			ans+=cnt>=lim;
//	printf("ans=%d\n",ans);
	return ans;
}
void dfs(ci d){
	if(d==n+1){
		check();
		return;
	}
	for(int i=0;i<m;++i)
		if(cnt[i])
			--cnt[i],a[d]=i,dfs(d+1),++cnt[i];
}
ll Sum(ll l,ll r){
	return (l+r)*(r-l+1)/2;
}
ll C(ll x){
	return x*(x-1)/2;
}
ll gt(ll n,ll m){
	ll tmp=0;
	--m,tmp+=(ll)m*(n-m+1);
	tmp+=Sum(1,m-1);
	++m;
	return tmp;
}
int main(){
//	freopen("mex.in","r",stdin);
//	freopen("mex.out","w",stdout);
	scanf("%d%d%d%d",&m,&l,&r,&x),n=m*x;
	for(int i=0;i<m;++i){
		char c=getchar();
		while(c!='0'&&c!='1')c=getchar();
		n+=c=='1',cnt[i]=x+(c=='1'),pre[i]=cnt[i];
		if(i)pre[i]+=pre[i-1];
	}
	if(n<=200&&m<=200){
		ans[0]=C(n+1)%mod;
		for(int i=1;i<=m;++i){
			if(i<l||i>r)continue;
//			printf("i=%d\n",i);
			ci A=pre[i-1],B=n-pre[i-1];
			int cnt=A/i;
//			printf("A=%d B=%d cnt=%d\n",A,B,cnt);
//			cnt组,每组i个 
			if(cnt==1){
				int len=0;
				for(int p=1;p<=B/2;++p)tp[++len]=0;
				for(int p=1;p<=A;++p)tp[++len]=1;
				for(int p=B/2+1;p<=B;++p)tp[++len]=0;
				ans[i]=calc(i);
			}
			else{
				
				for(int x=0;x<=B;++x){
//					printf("x=%d\n",x);
					ll tmp=C(n+1)-gt(A,i);
//					printf("tmp=%lld\n",tmp);
					tmp-=C(x/2+1)+C(x-x/2+1)+(ll)(x/2)*(i-1)+(ll)(x-x/2)*(i-1);
//					printf("tmp=%lld\n",tmp);
					int res=B-x;//->cnt-1
					for(int p=1;p<cnt;++p){
						int b=res/(cnt-1)+(p<=res%(cnt-1));
						tmp-=C(b+1)+b*(i-1)*2;
					}
//					printf("x=%d tmp=%lld\n",x,tmp);
					ans[i]=max(ans[i],tmp);
				}
				
//				ll mx=-1;int id=0;
//				for(int x=0;x<=B;++x){
//					int len=0,res=B-x;
//					//res分为cnt-1组 
//					for(int p=1;p<=x/2;++p)tp[++len]=0;
//					for(int k=1;k<=cnt;++k){
//						for(int p=1;p<=i;++p)tp[++len]=1;
//						if(k<=A%i)tp[++len]=1;
//						if(k!=cnt){
//							for(int p=1;p<=res/(cnt-1);++p)tp[++len]=0;
//							if(k<=res%(cnt-1))tp[++len]=0;
//						}
//					}
//					for(int p=x/2+1;p<=x;++p)tp[++len]=0;
////					printf("x=%d val=%d\n",x,calc(i));
//					if(calc(i)>mx)mx=calc(i),id=x;
//					ans[i]=max(ans[i],(ll)calc(i));
//				}
//				printf("i=%d id=%d\n",i,id);
				
			}
		}
		int tmp=(ll)n*(n+1)/2%mod;
		--m,sub(tmp,(ll)m*(n-m+1)%mod);
		sub(tmp,Sum(1,m-1));
		++m;
		ans[m]=tmp;
	}
	else if(n==m&&x==1){
		ans[0]=C(n+1);
		for(int i=1;i<=m;++i){
			ci A=pre[i-1],B=n-pre[i-1];
			ans[i]=(ll)(B/2+1)*((B+1)/2+1)%mod;
		}
	}
	else if(l==m&&r==m){
		int ans=(ll)n*(n+1)/2%mod;
		--m,sub(ans,(ll)m*(n-m+1)%mod);
		sub(ans,Sum(1,m-1));
		++m;
		while(m--)ans=ans*233ll%mod;
		printf("%d",ans);
		return 0;
	}
	else if(m==2){
		ans[0]=(ll)n*(n+1)/2%mod;
		ans[1]=(ans[0]-cnt[1]+mod)%mod;
		ans[2]=(ans[0]-n+mod)%mod;
	}
	else{
		dfs(1);
	}
//	for(int i=0;i<=m;++i)printf("i=%d ans=%lld\n",i,ans[i]);
	int res=0;
	for(int i=0,tmp=1;i<=r;++i,tmp=tmp*233ll%mod)
		if(i>=l)
			res^=ans[i]%mod*tmp%mod;
	printf("%d",res);
	return 0;
}

詳細信息

Subtask #1:

score: 5
Accepted

Test #1:

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

input:

2 0 2 2
01

output:

541257

result:

ok 1 number(s): "541257"

Test #2:

score: 0
Accepted
time: 1ms
memory: 10092kb

input:

4 1 4 2
00001

output:

525797597

result:

ok 1 number(s): "525797597"

Test #3:

score: 0
Accepted
time: 0ms
memory: 10056kb

input:

9 0 9 1
000000000

output:

711136343

result:

ok 1 number(s): "711136343"

Test #4:

score: 0
Accepted
time: 0ms
memory: 10092kb

input:

1 0 1 9
0

output:

10456

result:

ok 1 number(s): "10456"

Test #5:

score: 0
Accepted
time: 1ms
memory: 7992kb

input:

2 1 2 3
11


output:

1518844

result:

ok 1 number(s): "1518844"

Subtask #2:

score: 15
Accepted

Dependency #1:

100%
Accepted

Test #6:

score: 15
Accepted
time: 1ms
memory: 9892kb

input:

21 0 21 9
111010011100100100000

output:

171658329

result:

ok 1 number(s): "171658329"

Test #7:

score: 0
Accepted
time: 4ms
memory: 9904kb

input:

200 0 200 1
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

output:

287932632

result:

ok 1 number(s): "287932632"

Test #8:

score: 0
Accepted
time: 2ms
memory: 8052kb

input:

120 3 119 1
101000110101001100011100001011101110101010000011101110010101101000111100111100001001010010110001110011001010110001101111

output:

856785458

result:

ok 1 number(s): "856785458"

Test #9:

score: 0
Accepted
time: 1ms
memory: 7980kb

input:

2 0 2 99
10

output:

67513337

result:

ok 1 number(s): "67513337"

Subtask #3:

score: 0
Time Limit Exceeded

Dependency #2:

100%
Accepted

Test #10:

score: 0
Time Limit Exceeded

input:

10 1 9 499
0110011010

output:


result:


Subtask #4:

score: 5
Accepted

Test #14:

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

input:

2 0 1 114514
10

output:

934764137

result:

ok 1 number(s): "934764137"

Test #15:

score: 0
Accepted
time: 1ms
memory: 10044kb

input:

2 0 1 1919810
01

output:

685371514

result:

ok 1 number(s): "685371514"

Test #16:

score: 0
Accepted
time: 1ms
memory: 10032kb

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: 12ms
memory: 13836kb

input:

1000000 1000000 1000000 928
01100010010000000101111110001111011101111000011110100101011110011001001000011000110101101100111110000100101010111001111100010011100110000000111110110100001100000000011101100001010001010000010000001001000110011111010101111100001001110110010100000011000010010001111010011100...

output:

-277033125

result:

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

Subtask #6:

score: 10
Accepted

Test #19:

score: 10
Accepted
time: 9ms
memory: 22840kb

input:

1000000 0 1000000 1
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

852768823

result:

ok 1 number(s): "852768823"

Test #20:

score: 0
Accepted
time: 10ms
memory: 22116kb

input:

1000000 0 1000000 1
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

852768823

result:

ok 1 number(s): "852768823"

Subtask #7:

score: 0
Time Limit Exceeded

Test #21:

score: 0
Time Limit Exceeded

input:

1000000 0 9823 627
01110001011101001100010011100101001011000011011110001101010000000101010111110111110010010001110100101001111000111100011101111001000000100111000010010100010101110110111110100010101010001110111001100011010001111000101010000110010010101110101010111110110001110111111000001110000110011...

output:


result:


Subtask #8:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

0%

Subtask #9:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

0%