You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
686 B
31 lines
686 B
|
|
// https://www.cnblogs.com/rgbit/p/12863617.html
|
|
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
|
|
typedef unsigned long long ULL;
|
|
const int N = 1e5 + 10;
|
|
const int M = 1e6 + 10;
|
|
const ULL KEY = 100000007;
|
|
char s[M], p[N];
|
|
int n, m;
|
|
|
|
void match() {
|
|
ULL h = 1;
|
|
for (int i = 0; i < n; i++) h *= KEY;
|
|
|
|
ULL ah = 0, bh = 0;
|
|
for (int i = 0; i < n; i++) ah = ah * KEY + s[i];
|
|
for (int i = 0; i < n; i++) bh = bh * KEY + p[i];
|
|
for (int i = 0; i <= m - n; i++) {
|
|
if (ah == bh) printf("%d ", i);
|
|
if (i < m - n) ah = ah * KEY + s[i + n] - s[i] * h;
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
cin >> n >> p >> m >> s;
|
|
|
|
match();
|
|
return 0;
|
|
} |