Hello, PastePlz!

Paste Time: 2023-06-22 12:19:35.161031373 +08:00:00
//https://www.luogu.com.cn/problem/P3375
#include <bits/stdc++.h>
using namespace std;
int nxt[1000005];
void getnxt(string s) {
	int n = s.length();
	for (int i = 1, j = 0; i < n; i++) {
		while (j && s[i] != s[j]) {
			j = nxt[j];
		}
		if (s[i] == s[j]) {
			nxt[i + 1] = ++j;
		} else {
			nxt[i + 1] = 0;
		}
	}
}
void match(string s, string t) {
	int n = s.length(), Tlen = t.length();
	for (int i = 0, j = 0; i < n; i++) {
		while (j && s[i] != t[j]) {
			j = nxt[j];
		}
		if (s[i] == t[j]) {
			j++;
		}
		if (j == Tlen) {
			cout << i - Tlen + 2 << '\n';
		}
	}
}
int main() {
	ios::sync_with_stdio(false), cin.tie(nullptr);
	string s, t;
	cin >> s >> t;
	getnxt(t), match(s, t);
	for (int i = 1, Tlen = t.length(); i <= Tlen; i++) {
		cout << nxt[i] << ' ';
	}
	return 0;
}