QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#765171 | #7512. Almost Prefix Concatenation | ucup-team4352# | WA | 3ms | 14152kb | C++23 | 2.1kb | 2024-11-20 12:51:05 | 2024-11-20 12:51:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
const int mod=2000223479;
const int p=998244353;
char s[maxn],t[maxn];
int n,m;
ll sum1[maxn],sum2[maxn],qp[maxn];
void Init() {
int N=max(n,m);
qp[0]=1;
for(int i=1;i<=N;++i) qp[i]=qp[i-1]*1373%mod;
for(int i=1;i<=n;++i) sum1[i]=(sum1[i-1]*1373+(s[i]-'a'+1))%mod;
for(int i=1;i<=m;++i) sum2[i]=(sum2[i-1]*1373+(t[i]-'a'+1))%mod;
}
inline ll query1(int l,int r) {
return (sum1[r]-sum1[l-1]*qp[r-l+1]%mod)%mod;
}
inline ll query2(int l,int r) {
return (sum2[r]-sum2[l-1]*qp[r-l+1]%mod)%mod;
}
int dp2[maxn],dp1[maxn],dp0[maxn];
int lazy2[maxn<<2],lazy1[maxn<<2],lazy0[maxn<<2];
inline void add(int &x,int y) {
x+=y;
if(x>=p) x-=p;
}
void update(int rt,int l,int r,int L,int R,int p) {
if(L<=l&&R>=r) {
int res=dp0[p];
add(lazy0[rt],res);
add(res,dp1[p]),add(lazy1[rt],res);
add(res,dp1[p]),add(res,dp2[p]),add(lazy2[rt],res);
return;
}
int mid=l+r>>1;
if(L<=mid) update(rt<<1,l,mid,L,R,p);
if(R>mid) update(rt<<1|1,mid+1,r,L,R,p);
}
void query(int rt,int l,int r,int p) {
add(dp0[p],lazy0[rt]);
add(dp1[p],lazy1[rt]);
add(dp2[p],lazy2[rt]);
if(l==r) return;
int mid=l+r>>1;
if(p<=mid) query(rt<<1,l,mid,p);
else query(rt<<1|1,mid+1,r,p);
}
void solve(int rt,int l,int r,int p) {
if(l==r) {
lazy0[rt]=1;
return;
}
int mid=l+r>>1;
solve(rt<<1,l,mid,p);
}
int main() {
scanf("%s%s",s+1,t+1);
n=strlen(s+1),m=strlen(t+1);
Init();
solve(1,0,n,0);
for(int i=1;i<=n;++i) {
dp0[i-1]=dp1[i-1]=dp2[i-1]=0;
query(1,0,n,i-1);
int now=1;
int p=i;
int l=i,r=min(n,i+m-1);
while(l<=r) {
int mid=l+r>>1;
if(query1(p,mid)==query2(now,now+mid-i)) l=mid+1;
else r=mid-1;
}
if(l>n||l-i+1>m) l--;
if(l<n&&l-i+1<m) {
p=l+1,now=p-i+1;
l=p,r=min(n,i+m-1);
while(l<=r) {
int mid=l+r>>1;
if(query1(p,mid)==query2(now,now+mid-p)) l=mid+1;
else r=mid-1;
}
l--;
}
update(1,0,n,i,l,i-1);
}
dp0[n]=dp1[n]=dp2[n]=0;
query(1,0,n,n);
printf("%lld\n",dp2[n]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 14092kb
input:
ababaab aba
output:
473
result:
ok 1 number(s): "473"
Test #2:
score: 0
Accepted
time: 2ms
memory: 14152kb
input:
ac ccpc
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: -100
Wrong Answer
time: 3ms
memory: 14092kb
input:
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...
output:
715622842
result:
wrong answer 1st numbers differ - expected: '75038697', found: '715622842'