QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#200119 | #7512. Almost Prefix Concatenation | ucup-team1479# | WA | 0ms | 18100kb | C++17 | 3.2kb | 2023-10-04 15:25:29 | 2023-10-04 15:25:29 |
Judging History
answer
#include<bits/stdc++.h>
#define RI int
#define err puts("asd")
#define ll long long
#define ull unsigned long long
#define LL __int128
#define db double
#define mk make_pair
#define FL fflush(stdout)
#define eb emplace_back
#define FR(u,v) for(int i=h[u],v=a[i].t;i;i=a[i].n,v=a[i].t)
#define FB(x,z,y) for(int y=LG[(x)&-(x)],z=x;z;z^=z&-z,y=LG[z&-z])
#define FS(x,y) for(int y=x;y;y=(y-1)&x)
#define mem(a,b) memset(a,b,sizeof a)
#define yes puts("Yes")
#define no puts("No")
#define gg puts("-1")
#define vc vector
#define ex exit(0)
#define fi first
#define se second
#define int long long
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
using namespace std;
const db eps=1e-10;
const int inf=2e9+5;
const ll INF=1e18;
const int mod=998244353;
inline ll power(ll x,int y){
ll t=1;
while(y){
if(y&1) t=t*x%mod;
x=x*x%mod;y>>=1;
}
return t;
}
inline void gt(int &x,int &y){if(x>y) swap(x,y);}
inline void cmax(int &x,int y){x<y?x=y:0;}
inline void cmin(int &x,int y){x>y?x=y:0;}
inline void AD(int &x,int y){x+=y;if(x>=mod) x-=mod;}
inline ll read(){
ll s=0;char c=getchar();bool f=0;
while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}
while(c>='0'&&c<='9') s=(s<<1)+(s<<3)+c-48,c=getchar();
return f?-s:s;
}
const int N=2e6+5;
const int P=13331;
const int P1=13331;
ull F[N],F1[N],H1[N],H[N],pw[N],pw1[N];
ll f[N],g[N],h[N],tong1[N],tong2[N],tong3[N],tmp1,tmp2,tmp3;
int n,m,R[N];
char s[N],t[N];
inline ull get1(int x,int y){
return F[y]-F[x-1]*pw[y-x+1];
}
inline ull g1(int x,int y){
return F1[y]-F1[x-1]*pw1[y-x+1];
}
inline ull get2(int x,int y){
return H[y]-H[x-1]*pw[y-x+1];
}
inline ull g2(int x,int y){
return H1[y]-H1[x-1]*pw1[y-x+1];
}
signed main(){
ll op,x=0,y=0,z=0,u=0,v=0;
//freopen("1.in","r",stdin);
//freopen("1.out","w",stdout);
scanf("%s%s",s+1,t+1);
n=strlen(s+1);m=strlen(t+1);
pw[0]=pw1[0]=1;
for(RI i=1;i<=n;++i) pw[i]=pw[i-1]*P,pw1[i]=pw1[i-1]*P1,F[i]=F[i-1]*P+s[i],F1[i]=F1[i-1]*P1+s[i];
for(RI i=1;i<=m;++i) pw[i]=pw[i-1]*P,pw1[i]=pw1[i-1]*P1,H[i]=H[i-1]*P+t[i],H1[i]=H1[i-1]*P1+t[i];
RI l,r,mid,pos;
for(RI i=1;i<=n;++i){
l=i,r=n;pos=i-1;
while(l<=r){
mid=l+r>>1;
if(get1(i,mid)==H[mid-i+1]&&g1(i,mid)==H1[mid-i+1]) pos=mid,l=mid+1;
else r=mid-1;
}
//cout<<"A "<<pos<<endl;
x=l=pos+2;r=n;y=pos-i+3;pos=l-1;
while(l<=r){
mid=l+r>>1;
if(get1(x,mid)==get2(y,y-x+mid)&&g1(x,mid)==g2(y,y-x+mid)) pos=mid,l=mid+1;
else r=mid-1;
}
R[i]=min(pos,n);
R[i]=min(R[i],i+m-1);
cout<<R[i]<<endl;
}
h[0]=g[0]=1;
for(RI i=0;i<=n;++i){
AD(tmp1,tong1[i]);
AD(tmp2,tong2[i]);
AD(tmp3,tong3[i]);
if(i) f[i]=tmp1,g[i]=tmp2,h[i]=tmp3;
if(i!=n){
tong1[i+1]=(tong1[i+1]+f[i]+g[i])%mod;
tong2[i+1]=(tong2[i+1]+g[i]+h[i]*2)%mod;
tong3[i+1]=(tong3[i+1]+h[i])%mod;
tong1[R[i+1]+1]=(tong1[R[i+1]+1]-(f[i]+g[i])%mod+mod)%mod;
tong2[R[i+1]+1]=(tong2[R[i+1]+1]-(h[i]*2+g[i])%mod+mod)%mod;
tong3[R[i+1]+1]=(tong3[R[i+1]+1]-h[i]+mod)%mod;
}
/*for(RI j=i+1;j<=R[i+1];++j){
f[j]=(f[j]+f[i]+g[i])%mod;
g[j]=(g[j]+g[i]+h[i]*2)%mod;
h[j]=(h[j]+h[i])%mod;
}*/
}
cout<<f[n]<<endl;
return 0;
}
//颓入膏肓,没救了,有无神医相救?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 18100kb
input:
ababaab aba
output:
3 2 5 4 6 7 7 473
result:
wrong answer 1st numbers differ - expected: '473', found: '3'