因为要删去1个串(读错题),所以就直接二分搞就好了。

需要预处理出2个分别从头到尾,或从尾到头需要多长a串的数组,然后二分删去多长就好了。

 #include<bits/stdc++.h>
#define LL long long
#define N 100005
#define lowbit(x) x&(-x)
using namespace std;
inline int ra()
{
int x=,f=; char ch=getchar();
while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
return x*f;
}
char a[N], b[N];
int fl[N], fr[N];
int la, lb, i, j, mid, l, r, a1, a2;
int main()
{
scanf("%s%s",a+,b+);
la=strlen(a+); lb=strlen(b+);
for (i=,fl[]=j=; b[i]; i++)
{
for (j++; j<=la && a[j]!=b[i]; j++);
fl[i]=j;
}
for (i=lb, fr[lb+]=j=la+; b[i]; i--)
{
for (j--; j> && a[j]!=b[i]; j--);
fr[i]=j;
}
for (l=,r=lb; l<=r;)
{
mid=(l+r)>>;
for (i=; i+mid<=lb; i++)
if (fl[i]<fr[i+mid+]) break;
if (i+mid<=lb) a1=i,a2=mid+i+,r=mid-;
else l=mid+;
}
for (int i=; i<=a1; i++) putchar(b[i]);
for (int i=a2; i<=lb; i++) putchar(b[i]);
if (a2-a1>lb) putchar('-');
return ;
}
05-14 05:35