QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#768316#9614. 分治zhouhuanyi100 ✓2133ms53000kbC++143.7kb2024-11-21 09:12:282024-11-21 09:12:28

Judging History

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

  • [2024-11-21 09:12:28]
  • 评测
  • 测评结果:100
  • 用时:2133ms
  • 内存:53000kb
  • [2024-11-21 09:12:28]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#define N 400002
#define mod 998244353
using namespace std;
struct reads
{
	int num,data;
};
string s;
int ps,F[N+1],delta[N+1],delta2[N+1],fac[N+1],invfac[N+1],pw2[N+1],sz,Base,ans;
vector<int>v[N+1];
vector<int>v2[N+1];
vector<reads>v3[N+1];
vector<reads>v4[N+1];
int fast_pow(int a,int b)
{
	int res=1,mul=a;
	while (b)
	{
		if (b&1) res=1ll*res*mul%mod;
		mul=1ll*mul*mul%mod,b>>=1;
	}
	return res;
}
int C(int x,int y)
{
	return 1ll*fac[x]*invfac[y]%mod*invfac[x-y]%mod;
}
int MD(int x)
{
	return x>=mod?x-mod:x;
}
int MD2(int x)
{
	return x<0?x+mod:x;
}
void Adder(int &x,int d)
{
	x=x+d>=mod?x+d-mod:x+d;
	return;
}
void Adder2(int &x,int d)
{
	x=x+d<0?x+d+mod:x+d;
	return;
}
int calc(int a,int n)
{
	int d,res=0;
	for (int i=0;(a+2)*i<=n;++i)
	{
		d=n-(a+2)*i;
		if (!(i&1)) Adder(res,1ll*C(d+i,d)*pw2[d]%mod);
		else Adder2(res,-1ll*C(d+i,d)*pw2[d]%mod);
	}
	return res;
}
int solve(int a,int b,int n)
{
	int res=0;
	Adder(res,calc(a,n));
	if (n>=b+1) Adder2(res,-calc(a,n-b-1));
	return res;
}
void get(int a,int b,int n)
{
	Adder(ans,1ll*pw2[n]*(sz+1)%mod),a=max(a,b);
	if (a<=Base) v[a].push_back(n),v2[a].push_back(n+b-1);
	if (max(a,Base+1)+2<=n) v3[n/(max(a,Base+1)+2)].push_back((reads){max(a,Base+1),n});
	if ((max(a,Base+1)<<1)+2<=n+b-1) v4[(n+b-1-max(a,Base+1))/(max(a,Base+1)+2)].push_back((reads){max(a,Base+1),n+b-1});
	if (max(a,Base+1)<=sz-1) Adder2(ans,-1ll*(sz-max(a,Base+1))*pw2[n]%mod);
	if (max(a,Base+1)<=min(sz-1,n+b-1)) Adder(ans,MD2(pw2[n+b-max(a,Base+1)]-pw2[n+b-1-min(sz-1,n+b-1)]));
	return;
}
int main()
{
	int d,maxn;
	fac[0]=1;
	for (int i=1;i<=N;++i) fac[i]=1ll*fac[i-1]*i%mod;
	invfac[N]=fast_pow(fac[N],mod-2);
	for (int i=N-1;i>=0;--i) invfac[i]=1ll*invfac[i+1]*(i+1)%mod;
	pw2[0]=1;
	for (int i=1;i<=N;++i) pw2[i]=2ll*pw2[i-1]%mod;
	cin>>s,ans=1ll*pw2[s.length()-1]*s.length()%mod;
	for (int i=0;i+1<s.length();++i) Adder2(ans,-solve(i,i,s.length()-1));
	d=maxn=1,sz=s.length()+1,Base=sqrt(sz);
	for (int i=1;i<s.length();++i)
	{
		if (s[i]=='1') get(maxn,d+1,s.length()-i-1),d=0;
		else maxn=max(maxn,++d);
	}
	for (int i=Base;i>=0;--i)
	{
		F[0]=1;
		for (int j=1;j<=(sz<<1)-i;++j) F[j]=j<=i+1?2ll*F[j-1]%mod:(2ll*F[j-1]-F[j-i-2]+mod)%mod;
		for (int j=0;j<=(sz<<1)-i;++j) Adder(delta[j],F[j]),Adder(delta2[j+i],F[j]);
		for (int j=0;j<v[i].size();++j) Adder2(ans,-delta[v[i][j]]);
		for (int j=0;j<v2[i].size();++j) Adder(ans,delta2[v2[i][j]]);
	}
	for (int i=0;i<=sz;++i) delta[i]=pw2[i];
	for (int i=1;i<=sz/(Base+3);++i)
	{
		for (int j=0;j<=sz;++j) delta[j]=1ll*delta[j]*(j+i)%mod,F[j]=delta[j];
		for (int j=i;j<=sz;++j) Adder(F[j],F[j-i]);
		if (!(i&1))
		{
			for (int j=i;j<=sz/(Base+3);++j)
				for (int k=0;k<v3[j].size();++k)
					Adder2(ans,-1ll*F[v3[j][k].data-(v3[j][k].num+2)*i]*invfac[i]%mod);
		}
		else
		{
			for (int j=i;j<=sz/(Base+3);++j)
				for (int k=0;k<v3[j].size();++k)
					Adder(ans,1ll*F[v3[j][k].data-(v3[j][k].num+2)*i]*invfac[i]%mod);
		}
	}
	for (int i=0;i<=(sz<<1);++i) delta[i]=pw2[i];
	for (int i=1;i<=(sz<<1)/(Base+3);++i)
	{
		for (int j=0;j<=(sz<<1);++j) delta[j]=1ll*delta[j]*(j+i)%mod,F[j]=delta[j];
		for (int j=i+1;j<=(sz<<1);++j) Adder(F[j],F[j-i-1]);
		if (!(i&1))
		{
			for (int j=i;j<=(sz<<1)/(Base+3);++j)
				for (int k=0;k<v4[j].size();++k)
					Adder(ans,1ll*F[v4[j][k].data-(v4[j][k].num+2)*i-v4[j][k].num]*invfac[i]%mod);
		}
		else
		{
			for (int j=i;j<=(sz<<1)/(Base+3);++j)
				for (int k=0;k<v4[j].size();++k)
					Adder2(ans,-1ll*F[v4[j][k].data-(v4[j][k].num+2)*i-v4[j][k].num]*invfac[i]%mod);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

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

input:

110

output:

15

result:

ok 1 number(s): "15"

Test #2:

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

input:

101

output:

12

result:

ok 1 number(s): "12"

Subtask #2:

score: 10
Accepted

Dependency #1:

100%
Accepted

Test #3:

score: 10
Accepted
time: 16ms
memory: 46628kb

input:

111110

output:

198

result:

ok 1 number(s): "198"

Test #4:

score: 10
Accepted
time: 17ms
memory: 49104kb

input:

1001001

output:

253

result:

ok 1 number(s): "253"

Subtask #3:

score: 20
Accepted

Dependency #2:

100%
Accepted

Test #5:

score: 20
Accepted
time: 14ms
memory: 49264kb

input:

10100011000100111

output:

386882

result:

ok 1 number(s): "386882"

Test #6:

score: 20
Accepted
time: 11ms
memory: 49144kb

input:

111010011111010110

output:

1107742

result:

ok 1 number(s): "1107742"

Subtask #4:

score: 5
Accepted

Test #7:

score: 5
Accepted
time: 13ms
memory: 48668kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

output:

412796008

result:

ok 1 number(s): "412796008"

Test #8:

score: 5
Accepted
time: 15ms
memory: 49652kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

output:

818656648

result:

ok 1 number(s): "818656648"

Subtask #5:

score: 5
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #9:

score: 5
Accepted
time: 11ms
memory: 47116kb

input:

10000000100000010010011110111101101110000000000001100000011000111111010011010101010000101001110110010001100110000110111101000101001111101111001010001001011101011111010000100010111100110000001101111

output:

703266161

result:

ok 1 number(s): "703266161"

Test #10:

score: 5
Accepted
time: 8ms
memory: 48160kb

input:

110100000100001000101000010010101000110111101010110000101001001100100111000011100101110110010000001111010011101001111110110010001110011101001111010101100100010011101010101111111111010110001100100110

output:

330527406

result:

ok 1 number(s): "330527406"

Subtask #6:

score: 5
Accepted

Dependency #4:

100%
Accepted

Test #11:

score: 5
Accepted
time: 7ms
memory: 48664kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

340672883

result:

ok 1 number(s): "340672883"

Test #12:

score: 5
Accepted
time: 8ms
memory: 48352kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

555946758

result:

ok 1 number(s): "555946758"

Subtask #7:

score: 10
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Test #13:

score: 10
Accepted
time: 12ms
memory: 50004kb

input:

110011100110101000000110101010111111001101101011010110100100110010111110110110000111011001110000101111110111011111000110001011011011101100001100100011010010111111010110010000101001001000100001100100000001000111110100000101001011100001100011011110110101101111110011100111001010001010001111001110111100...

output:

324123594

result:

ok 1 number(s): "324123594"

Test #14:

score: 10
Accepted
time: 12ms
memory: 49576kb

input:

110100110100110110001011100000011010000010000101100100001101100100110000101000111001111100001110001001101010110010111101000100111010001011001110101010001101111010000011000010110011000011100101110100000001011100111000101111010100001101011010100101110000010001101001000100111001101101110000101101011011...

output:

209285599

result:

ok 1 number(s): "209285599"

Subtask #8:

score: 10
Accepted

Dependency #6:

100%
Accepted

Test #15:

score: 10
Accepted
time: 738ms
memory: 50144kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

468567454

result:

ok 1 number(s): "468567454"

Test #16:

score: 10
Accepted
time: 1612ms
memory: 50840kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

12752860

result:

ok 1 number(s): "12752860"

Subtask #9:

score: 25
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #8:

100%
Accepted

Test #17:

score: 25
Accepted
time: 2133ms
memory: 53000kb

input:

101100010100101011010110001111101101001010000111001111000100110110010111101100011011011111010110000000011110000010100110111110110001101001101101001110101110011000010100100101000011000010000101011001011011000000100111011110100010000100001101011110100101110000100011000101100000111111100110000111010000...

output:

711712397

result:

ok 1 number(s): "711712397"

Test #18:

score: 25
Accepted
time: 1972ms
memory: 52852kb

input:

110101110100100010101100000110000110101101111100110011100111111110000101111001101001111000110111100111110111010001000010111111110000001001011110101110001011010010010011101000110110000110110101000100111000100110101111011101111101000010000101001001000010011011000011001100111111011000111000010000100111...

output:

171668334

result:

ok 1 number(s): "171668334"

Test #19:

score: 25
Accepted
time: 1882ms
memory: 50848kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

397846555

result:

ok 1 number(s): "397846555"

Test #20:

score: 25
Accepted
time: 1706ms
memory: 51980kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

592103795

result:

ok 1 number(s): "592103795"

Extra Test:

score: 0
Extra Test Passed