QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#239411#7512. Almost Prefix ConcatenationHarry27182WA 2ms11836kbC++142.0kb2023-11-04 20:35:362023-11-04 20:35:37

Judging History

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

  • [2023-11-04 20:35:37]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11836kb
  • [2023-11-04 20:35:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int MOD=998244353,mod1=1000000007,mod2=1000000231,N=1000005;
int f[N][3],hs1[N],hs2[N],ht1[N],ht2[N],p1[N],p2[N],n,m;char s[N],t[N];
int query(int *h,int *p,int l,int r,int mod){return (h[r]-1ll*h[l-1]*p[r-l+1]%mod+mod)%mod;}
struct BIT
{
	int tr[N];
	void change(int x,int v){for(int i=x;i<=n;i+=i&(-i))tr[i]=(tr[i]+v)%MOD;}
	int query(int x){int res=0;for(int i=x;i;i-=i&(-i))res=(res+tr[i])%MOD;return res;}
}tr0,tr1,tr2;
int main()
{
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
    cin.tie(0)->sync_with_stdio(0);
    cin>>(s+1)>>(t+1);
    n=strlen(s+1),m=strlen(t+1);p1[0]=p2[0]=1;
    for(int i=1;i<=max(n,m);i++)
    {
    	p1[i]=1ll*p1[i-1]*131%mod1;
    	p2[i]=1ll*p2[i-1]*137%mod2;
	}
	for(int i=1;i<=n;i++)
	{
		hs1[i]=(1ll*131*hs1[i-1]%mod1+s[i])%mod1;
		hs2[i]=(1ll*137*hs2[i-1]%mod2+s[i])%mod2;
	}
	for(int i=1;i<=m;i++)
	{
		ht1[i]=(1ll*131*ht1[i-1]%mod1+t[i])%mod1;
		ht2[i]=(1ll*137*ht2[i-1]%mod2+t[i])%mod2;
	}
	for(int i=0;i<=n;i++)
	{
		f[i][0]=(i==0?1:tr0.query(i));f[i][1]=(i==0?0:tr1.query(i));f[i][2]=(i==0?0:tr2.query(i));
		int l=1,r=min(m,n-i),len1=0,len2=0;
		while(l<=r)
		{
			int mid=(l+r)>>1;
			if(query(hs1,p1,i+1,i+mid,mod1)==query(ht1,p1,1,mid,mod1)
			&&query(hs2,p2,i+1,i+mid,mod2)==query(ht2,p2,1,mid,mod2))l=mid+1,len1=mid;
			else r=mid-1;
		}
		l=1;r=min(m-len1-1,n-i-len1-1);
		while(l<=r)
		{
			int mid=(l+r)>>1;
			if(query(hs1,p1,i+len1+1+1,i+len1+1+mid,mod1)==query(ht1,p1,len1+1+1,len1+1+mid,mod1)
			&&query(hs2,p2,i+len1+1+1,i+len1+1+mid,mod2)==query(ht2,p2,len1+1+1,len1+1+mid,mod2))l=mid+1,len2=mid;
			else r=mid-1;
		}
		int val0=f[i][0],val1=(f[i][1]+f[i][0])%MOD,val2=((f[i][2]+2*f[i][1]%MOD)%MOD+f[i][0])%MOD;
		l=i+1,r=min(min(i+len1+1+len2,i+m),n);
		tr0.change(l,val0);tr0.change(r+1,-val0);
		tr1.change(l,val1);tr1.change(r+1,-val1);
		tr2.change(l,val2);tr2.change(r+1,-val2);
	}
	cout<<f[n][2]<<'\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 11636kb

input:

ababaab
aba

output:

473

result:

ok 1 number(s): "473"

Test #2:

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

input:

ac
ccpc

output:

5

result:

ok 1 number(s): "5"

Test #3:

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

input:

qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

75038697

result:

ok 1 number(s): "75038697"

Test #4:

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

input:

lvvvllvllvllvllllllllvvvllvlllvvlvlvllvlvvlvvvvlvvllllllvvlvlvvlllvvlvlvllllllvlvvvvvvlllvvvllvlvvvlvvlllvvvvvvlvlllvvvvlvvvvvlvvlvvlllvvllvvllvlvlvlvlvllllvvllvvllvlllvvvllllvvlvvllvvvvlvlvvlvvlllvvvvvvvvlvvlvlllvllvvvvllvvvlvvvvvvlvlllvllllvllllllllvvllllllvlvvlvvvlvllllvllvlvvllllllvlvvvlvlvlvvvl...

output:

538419149

result:

ok 1 number(s): "538419149"

Test #5:

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

input:

fzztyyyfztzzfzyztftyfzyyzzzztyyfzttzttztyzztyyyfyyftyfyfzzffyzffytttzttyzzftyfyfyftyyfzyzffyfyyzztzyyttyfyztfyfzyfzfzyftttfyyfyytzyyzfyyyzztfttzyyytzzffytyzyyyyfzfftftzzztyfftfzfzytftfttytfyzfytzfzztttttzzyztyftzzzfzfzfffttyztzfftfftyfyffztzyffttyyfyfzytytyyttfzzfyyytzzftzyyfftftyytyffzffztfytfyyyty...

output:

867833603

result:

ok 1 number(s): "867833603"

Test #6:

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

input:

xauxlgtqbsianlzjzglalnbtlujfrkfdqgczpmididmtamzeablrbrbjgtsdkzzcfhvcpdawqkrgdsereirlxbizhbsxlcbtgwwshekbhatqonvgupswcowythifpoubxkuoxuuisnzolzwektdcaouxbkhofvdqzmjulmhgqjxwzhgrzmorhqkgekntbzsxgvjtehfbterrhhjhqggzrqiqmcshzwpfoburpyfoehqgtitesyaekhlzcvxzdqmunyrlrhbrjoigdjzpcgptyoiowwnmqrxucxixxydurbdh...

output:

301464023

result:

ok 1 number(s): "301464023"

Test #7:

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

input:

tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt...

output:

816920406

result:

ok 1 number(s): "816920406"

Test #8:

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

input:

cxccxccccxccxccxcxxxccxxcxcxcxcxxcccxcxccccccxccccxccxcxcxxcxxcxcxxxcxcccxcxxxxxccxxcccxxccxxxccxccxxxxcxxccccxccxxcccxcccxxxccccxcxcxccccxxxxccxxxxxcxxxxxxcxxccxxcxcxcxxxxxcxxccxcxxxcccxcxxxccccccccxxxcccxcxxcxxxxccxxxcccccxcccxccccccxxcccxxcccxxxccxxcxccxcccxxxccxccxxxccxcxxxxccxxcxcxxcxxccxxxcxcx...

output:

206627037

result:

ok 1 number(s): "206627037"

Test #9:

score: -100
Wrong Answer
time: 0ms
memory: 11836kb

input:

vmqvvbbmvmmmqqvqvmmbbvqbqvbmmbqmvvbmmmqvqvbvqqmvbbmmvmvqbvmqqbqvqqvmvmmbqvvbvmvbqmqqbqqqbqqmvvmmbvvvbvvvbmqqvbqbmvvmvqqvbqbvvvqmvvvmvqqmvqbmbvmvmqmmbmqqqbbmvqbqbbqqbmmvmmqqqvvvqqqqqmmvvvvqmvmmmmvmqmqbbvbvvqmmmqbbmvqvmvmqbqbbbmqbqbqmqbqmqbmvvqmmvbmmbvbqqvmmmbbmbbmvmmvbmqmqbbqqbqqbbqmbmmmqbqbmvbmvmmmm...

output:

-537584998

result:

wrong answer 1st numbers differ - expected: '460659355', found: '-537584998'