CF914F题解
_WAlkingDead · · 题解
诈骗题。
如果你想用一些字符串科技,那你就成功地被骗了。
bitset
我们定义 bitset<N> res,b 其中 res 为答案, b 为初始字符串。
我们用 res 存下所有可能的左端点,当处理第 i 个字符时,res&=(b[c[i]]>>(i-1)) 即可,其中 c 为待匹配字符串。
最终的 res 就是匹配的所有左端点。
然后我们求出合法区间内 res 中 1 的个数即可。
修改就直接
时间复杂度
code
#include<iostream>
#include<cstdio>
#include<bitset>
#include<cstring>
using namespace std;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
const int N=1e5+5;
bitset<N> b[256],res;
char s[N],c[N];
int q,len;
int main(){
scanf("%s",s+1);
for(int i=1;i<=strlen(s+1);i++) b[s[i]][i]=1;
q=read();
while(q--){
int opt=read();
if(opt==1){
int i=read();
scanf("%s",c+1);
b[s[i]][i]=0;
b[c[1]][i]=1;
s[i]=c[1];
}
if(opt==2){
int l=read(),r=read();
scanf("%s",c+1);
res.set();
for(int i=1;i<=strlen(c+1);i++) res&=(b[c[i]]>>(i-1));
int lans=(res>>l).count(),rans=(res>>(r-strlen(c+1)+2)).count();
printf("%d\n",max(0,lans-rans));
}
}
return 0;
}