知识点:字符串哈希
这个题还是比较简单的,看了看字符串哈希就可以解决,但是貌似标签里面还有kmp,等明天复习一下kmp再用kmp做做,用字符串哈希的做法就是二分,外层是暴力枚举,第二层就是二分,然后这个题12分钟过了,比前面的容易,应该有个绿题的难度
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int N = 2e5 + 5;
const int P = 131;
int n, m, q, ans[N];
ull h1[N], h2[N], p[N];
string s1, s2;
int main() {
cin >> n >> m >> q;
cin >> s1 >> s2;
s1 = " " + s1;
s2 = " " + s2;
for (int i = 1; i <= n; i++) h1[i] = h1[i - 1] * P + s1[i];
for (int i = 1; i <= m; i++) h2[i] = h2[i - 1] * P + s2[i];
p[0] = 1;
for (int i = 1; i <= max(n, m); i++) p[i] = p[i - 1] * P;
for (int i = 1; i <= n; i++) {
int l = i - 1, r = min(n, i + m - 1);
while (l < r) {
int mid = (l + r + 1) >> 1;
ull t1 = h1[mid] - h1[i - 1] * p[mid - i + 1];
ull t2 = h2[mid - i + 1];
if (t1 == t2) l = mid;
else r = mid - 1;
}
ans[l - i + 1]++;
}
while (q--) {
int x;
cin >> x;
cout << ans[x] << endl;
}
return 0;
}