搁置了好几天,终于想通......
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<bitset>
using namespace std;
const int maxn = 1e5 + 10;
char s[maxn];
int q;
int cnt;
bitset<maxn> m[27], ans;
int main()
{
scanf("%s", s);
int len = strlen(s);
for(int i = 0; i < len; i++)
{
m[s[i] - 'a'][i + 1] = 1;
}
scanf("%d", &q);
int op;
char tmp[maxn];
for(int i = 0; i < q; i++)
{
scanf("%d", &op);
if(op == 1)
{
int pos;
char ch[5];
scanf("%d%s", &pos, ch);
char tt = ch[0];
m[s[pos - 1] - 'a'][pos] = 0;
m[tt - 'a'][pos] = 1;
s[pos - 1] = tt;
}
else
{
cnt = 0;
ans.set(); //全部位置1
int l, r;
scanf("%d%d%s", &l, &r, tmp);
int len = strlen(tmp);
for(int i = 0; i < len; i++)
{
ans &= m[tmp[i] - 'a'] >> i; //移动,利用相对位置拼出子串,如果ans[i] = 1表示以i开头长度为len(子串长度)的区间内有一个符合的解
}
int left = (ans >> l).count();
int right = (ans >> (r - len + 1 + 1)).count(); //根据ans[i]的含义,实际范围变为l ~ r - len + 1(包括边界),查看这个区间内1的个数,所以分别右移做差,因为bitset起始位为0,所以右移(x + 1), x为l 或者 r - len + 1
if(left < right) left = right;
printf("%d\n", left - right);
}
}
return 0;
}