QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#538013#7512. Almost Prefix ConcatenationYoralenWA 8ms14208kbC++142.1kb2024-08-30 20:52:302024-08-30 20:52:31

Judging History

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

  • [2024-08-30 20:52:31]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:14208kb
  • [2024-08-30 20:52:30]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int mod=998244353,B=233;
const int N=1000005,L=1000000;
int hs[N],hb[N],pw[N],m,n,rf[N];
char a[N],b[N];
int inc(int a,int b){a+=b;return a>=mod?a-mod:a;}
int dec(int a,int b){a-=b;return a<0?a+mod:a;}
int mul(int a,int b){return 1ll*a*b%mod;}
int powe(int a,int b){
	int v=1;
	while(b){
		if(b&1)v=mul(v,a);
		a=mul(a,a),b>>=1;
	}return v;
}
int Inv(int x){return powe(x,mod-2);}
int Cala(int l,int r){
	if(l>r)return 0;
	return dec(hs[r],mul(hs[l-1],pw[r-l+1]));
}
int Calb(int l,int r){
	if(l>r)return 0;
	return dec(hb[r],mul(hb[l-1],pw[r-l+1]));
}
int low(int x){return x&(-x);}
struct BIT{
	int cf[N];
	void Add(int p,int v){
		for(;p<=n;p+=low(p))cf[p]=inc(cf[p],v);
	}
	int Ask(int p){
		int s=0;
		for(;p;p-=low(p))s=inc(s,cf[p]);
		return s;
	}
}sq,sn,sc;
int main(){
	int i;
	scanf("%s",a+1);n=strlen(a+1);
	scanf("%s",b+1);m=strlen(b+1);
	for(i=1;i<=L;i++)pw[i]=mul(pw[i-1],B);
	for(i=1;i<=n;i++)hs[i]=inc(mul(hs[i],B),a[i]);
	for(i=1;i<=m;i++)hb[i]=inc(mul(hb[i],B),b[i]);
	for(i=1;i<=n;i++){
		int L=i-1,R=n,res=0,lcp=0;
		while(L<=R){
			int mid((L+R)>>1);
			int len=mid-i+1;
			if(len>m){R=mid-1;continue;}
			if(Cala(i,mid)==Calb(1,len)){
				res=mid;lcp=len;L=mid+1;
			}
			else R=mid-1;
		}
		if(res==n||res==n-1){rf[i]=n;continue;}
		if(lcp>=m){rf[i]=res;continue;}
		lcp++;if(lcp>=m){rf[i]=res+1;continue;}
		res++;L=res,R=n;
		while(L<=R){
			int mid((L+R)>>1);
			int len=mid-(res+1)+1;
			if(lcp+1+len-1>m){R=mid-1;continue;}
			if(Cala(res+1,mid)==Calb(lcp+1,lcp+1+len-1)){
				rf[i]=mid;L=mid+1;
			}
			else R=mid-1;
		}
	}
	//for(i=1;i<=n;i++){
	//	printf("%d ",rf[i]);
	//}putchar('\n');
	for(i=1;i<=n;i++){
		int Sq=sq.Ask(i-1);
		int Sn=sn.Ask(i-1);
		int Sc=sc.Ask(i-1);
		if(i==1)Sc++;
		int vq=inc(Sq,inc(mul(2,Sn),Sc));
		sq.Add(i,vq);sq.Add(rf[i]+1,mod-vq);
		int vn=inc(Sn,Sc);
		sn.Add(i,vn);sn.Add(rf[i]+1,mod-vn);
		int vc=Sc;
		sc.Add(i,vc);sc.Add(rf[i]+1,mod-vc);
	}
	printf("%d",sq.Ask(n));
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 14148kb

input:

ababaab
aba

output:

473

result:

ok 1 number(s): "473"

Test #2:

score: 0
Accepted
time: 8ms
memory: 13964kb

input:

ac
ccpc

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: -100
Wrong Answer
time: 4ms
memory: 14208kb

input:

qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

495807373

result:

wrong answer 1st numbers differ - expected: '75038697', found: '495807373'