QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#236607#7512. Almost Prefix ConcatenationKevin5307WA 6ms16256kbC++142.3kb2023-11-04 09:00:402023-11-04 09:00:40

Judging History

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

  • [2023-11-04 09:00:40]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:16256kb
  • [2023-11-04 09:00:40]
  • 提交

answer

//Author: Kevin5307
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
const ll mod=998244353,base=257;
ll hs[1000100],ht[1000100];
ll bp[1000100];
ll gets(int l,int r){return (hs[r]-hs[l-1]*bp[r-l+1]%mod+mod)%mod;}
ll gett(int l,int r){return (ht[r]-ht[l-1]*bp[r-l+1]%mod+mod)%mod;}
int p[1000100];
ll bit[3][1000100];
void upd(ll &a,ll b)
{
	a+=b;
	a%=mod;
}
void update(int x,int p,ll v)
{
	while(p<1000100)
	{
		upd(bit[x][p],v);
		p+=(p&(-p));
	}
}
ll query(int x,int p)
{
	ll ans=0;
	while(p)
	{
		upd(ans,bit[x][p]);
		p-=(p&(-p));
	}
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	bp[0]=1;
	for(int i=1;i<1000100;i++)
		bp[i]=bp[i-1]*base%mod;
	string s,t;
	cin>>s>>t;
	int n=sz(s),m=sz(t);
	for(int i=1;i<=n;i++)
		hs[i]=(hs[i-1]*base+s[i-1]);
	for(int i=1;i<=m;i++)
		ht[i]=(ht[i-1]*base+t[i-1]);
	for(int i=1;i<=n;i++)
	{
		int l=i-1,r=min(n,i+m-1);
		while(l<r)
		{
			int mid=(l+r+1)/2;
			if(gets(i,mid)==gett(1,mid-i+1))
				l=mid;
			else
				r=mid-1;
		}
		int p2=l+1;
		l=p2,r=min(n,i+m-1);
		while(l<r)
		{
			int mid=(l+r+1)/2;
			if(gets(p2+1,mid)==gett(p2-i+2,mid-i+1))
				l=mid;
			else
				r=mid-1;
		}
		p[i]=min(l,n);
		p[i]=min(p[i],i+m-1);
//		cerr<<p[i]<<endl;
	}
	update(0,1,1);
	update(0,2,-1);
//	update(1,1,1);
//	update(1,2,mod-1);
//	update(2,1,1);
//	update(2,2,mod-1);
	for(int i=1;i<=n;i++)
	{
		int l=i+1,r=p[i]+1;
		ll a0=query(0,i),a1=query(1,i),a2=query(2,i);
//		cerr<<a0<<" "<<a1<<" "<<a2<<endl;
		update(0,l,a0);
		update(0,r+1,mod-a0);
		update(1,l,(a0+a1)%mod);
		update(1,r+1,mod-(a0+a1)%mod);
		update(2,l,(a0+a1+a1+a2)%mod);
		update(2,r+1,mod-(a0+a1+a1+a2)%mod);
	}
	cout<<query(2,n+1)<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 15892kb

input:

ababaab
aba

output:

473

result:

ok 1 number(s): "473"

Test #2:

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

input:

ac
ccpc

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: -100
Wrong Answer
time: 6ms
memory: 16256kb

input:

qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

808668087

result:

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