QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#236609 | #7512. Almost Prefix Concatenation | Kevin5307 | WA | 7ms | 24440kb | C++14 | 2.8kb | 2023-11-04 09:02:38 | 2023-11-04 09:02:38 |
Judging History
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,base1=301;
ll hs[1000100],ht[1000100],hs1[1000100],ht1[1000100];
ll bp[1000100],bp1[1000100];
ll gets0(int l,int r){return (hs[r]-hs[l-1]*bp[r-l+1]%mod+mod)%mod;}
ll gett0(int l,int r){return (ht[r]-ht[l-1]*bp[r-l+1]%mod+mod)%mod;}
ll gets1(int l,int r){return (hs1[r]-hs1[l-1]*bp1[r-l+1]%mod+mod)%mod;}
ll gett1(int l,int r){return (ht1[r]-ht1[l-1]*bp1[r-l+1]%mod+mod)%mod;}
ll gets(int l,int r){return gets0(l,r)*mod+gets1(l,r);}
ll gett(int l,int r){return gett0(l,r)*mod+gett1(l,r);}
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;
bp1[0]=1;
for(int i=1;i<1000100;i++)
bp1[i]=bp1[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++)
hs1[i]=(hs1[i-1]*base1+s[i-1]);
for(int i=1;i<=m;i++)
ht1[i]=(ht1[i-1]*base1+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: 0
Wrong Answer
time: 7ms
memory: 24440kb
input:
ababaab aba
output:
110
result:
wrong answer 1st numbers differ - expected: '473', found: '110'