题目集1
A
https://vjudge.net/contest/412612#problem/A
求有多少个S子串满足长度是M*L,子串划分为M节长度为L的小子串,M节小子串的每一位都不同
解:哈希然后尺取
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define dec(i,a,b) for(ll i=(a);i>=(b);i--)
#define pll pair<ll,ll>
using namespace std;
ll INF = 0x7f7f7f7f7f7f7f7f;
const int N = 1e5 + 5;
ll mod = 998244353;
ull base[N], h[N];
ull gethash(ll l, ll r) {
return h[r] - h[l - 1] * base[r - l + 1];
}
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, m;
ll seed = 31;
base[0] = 1;
for (int i = 1; i < N; i++) {
base[i] = base[i - 1] * 31;
}
string s;
while (cin >> n >> m >> s) {
for (int i = 0; i < s.size(); i++) {
h[i] = h[i - 1] * seed + s[i];
}
ll ans = 0;
for (int i = 0; i<m && i+n*m < s.size(); i++) {
map<ull,ll> mp;
for (int j = i,k = 0; k < n; j += m,k++) {
mp[gethash(j, j + m - 1)]++;
}
if (mp.size() == n)
ans++;
for (int j = 0; j < (s.size() - n * m -