Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- #include <vector>
- #include <set>
- #include <map>
- #include <string>
- #include <cassert>
- #include <numeric>
- #include <queue>
- #include <cstdint>
- #include <string>
- #include <unordered_map>
- #include <unordered_set>
- #include <stack>
- using namespace std;
- #define int long long
- #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
- const long long INF = 1e18 + 7;
- const double EPS = 1e-9;
- const int MOD = 1e9 + 7;
- const int N = 2e3 + 10;
- const int K = 64;
- const int B = 500;
- inline void solve() {
- string s;
- cin >> s;
- int n = s.size();
- vector<int> z(n, 0);
- int l = 0, r = 0;
- for (int i = 1; i < n; ++i) {
- if (r >= i) {
- z[i] = min(z[i - l], r - i + 1);
- }
- while (z[i] + i < n && s[z[i] + i] == s[z[i]]) {
- ++z[i];
- }
- if (r < i + z[i] - 1) {
- l = i;
- r = i + z[i] - 1;
- }
- }
- for (int i = 1; i < n; ++i) {
- cout << z[i] << ' ';
- }
- }
- int32_t main() {
- IOS;
- // freopen("knight.in", "r", stdin);
- // freopen("knight.out", "w", stdout);
- int tt = 1;
- // cin >> tt;
- while (tt--) {
- solve();
- }
- return 0;
- }
- /*
- 1. 数组开够了没
- 2. 文件名写对了没,文件夹建了吗
- 3. 内存会不会MLE
- 4. 多测清空?
- 5. 调试删干净了没
- 6. 取模有没有溢出
- 7. 快速幂底数要取模,幂对 mod-1 取模
- 8. 前向星和欧拉序要开2倍数组
- 9. 比较函数如果值相同的话有没有第二优先级
- 10. 线段树 4 倍空间,线段树合并和可持久化线段树 32 倍空间
- 11. 看清楚 log 的底数是啥,log后面的数是啥
- 12. long long 只有正负 2^63-1
- */
- /*
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠿⠿⠻⠟⢛⣛⡿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣳
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣋⣉⡄⠀⣀⡀⠨⣙⣏⣉⣽⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⣿⡿⣿⢿⣿⣿⣿⡿⣟⣿⣯⣿⣷⣿⢾⣿
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⣛⣒⡛⢫⠤⣠⢤⣤⣤⣹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣻⣯⣿⢿⣿⢯⣿⣯⣿⣿⣻⣞⡷⣿⣽⣻⡽
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢮⣭⣉⡓⠺⠊⢉⠓⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡽⣿⣻⢿⡿⣯⢿⣷⢯⡷⣯⣟⠷⣯⡗⡿
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⣩⣿⣿⢿⣷⣄⡙⢮⠭⡁⢠⣬⣿⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣽⣯⢿⣽⡿⣾⣻⣽⣳⣞⣟⡧⣟⡽
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⠀⡴⠹⢿⣿⣀⣿⣿⣯⣍⢛⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⣾⡿⣯⣿⡽⣟⡾⣵⢫⣾⡱⢯⡜
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠁⢀⣞⣰⣀⣾⡷⠘⣿⣿⣟⣩⠙⠛⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣻⢷⣟⣿⢯⡷⣏⡟⣶⡹⢇⡞
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠁⣰⢯⣾⣿⣿⡿⠁⠀⠀⠼⢿⣿⠥⢤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣽⣟⡾⣟⣯⢿⡼⣹⢶⡹⢣⠞
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⣴⣿⣿⣿⣿⠟⠀⠀⠀⠀⠀⠀⠘⠺⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⢿⡽⣯⣟⢾⡱⣏⠵⣋⠎
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠻⢬⡙⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣽⣳⢯⣏⡗⣎⠳⡌⠆
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠙⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⣷⢻⡗⣮⡝⣬⢳⠉⡎
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⡿⣯⢷⣫⢗⡭⢎⢧⡙
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣿⣿⣿⣶⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢡⣀⢛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣟⣯⣟⣧⡟⡼⣉⢆⠣
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠹⣿⢿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠤⡂⠭⢊⠻⡹⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⣷⣻⣞⡽⣲⢍⡎⢇
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡀⢻⠆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⢡⠒⠐⢀⠀⠠⠐⡆⢯⡹⡹⢛⡯⢭⡹⣿⣿⣿⣿⣿⣿⣿⡿⣾⢯⣷⣻⣜⡳⢎⡜⠦
- ⣿⣿⣿⣿⣿⣿⣿⣿⠟⠛⠻⢷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⠀⠀⠀⠀⠀⠀⠀⡄⠠⢎⢦⡹⢄⡄⣌⣩⣝⠾⣡⢃⠡⠃⡘⢧⠿⣽⣻⣿⣿⣿⣿⣿⣽⣿⣟⣷⣻⡼⣝⢮⡙⡖
- ⣿⣿⣿⣿⣿⣿⣿⠃⣾⣷⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢉⣩⣁⣳⣶⣦⣤⣤⣈⣥⢛⡞⣶⣿⣜⣫⢝⣶⣫⢞⣡⣀⣒⣀⡴⣨⡽⣎⣿⣿⣿⣿⣿⣿⣿⣿⢾⣯⢷⣻⡜⣮⢱⢣
- ⣿⣿⣿⣿⣿⣿⣿⡇⣿⢻⠇⠛⢧⠀⠀⠀⠀⠀⠀⠾⠛⣉⣭⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢟⣿⣯⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣯⣿⢾⣯⢷⣻⣼⢣⢧
- ⣿⣿⣿⣿⣿⣿⣿⣿⡌⣿⠀⣶⣿⠃⠀⠀⠀⠀⢰⣶⡾⠟⠫⣈⢿⡿⠟⣨⣿⣿⣿⢿⡆⠀⠈⣿⣿⣿⣿⣿⡟⢹⣯⣿⡟⢻⣿⣿⣿⣿⣿⣿⣿⣿⡏⢸⣿⢯⣿⢯⡿⣟⡾⣏⣞
- ⣿⣿⣿⣿⣿⣿⣿⣿⣷⠸⡀⢿⡃⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣉⣛⠶⣿⣿⣿⣿⠟⣿⠃⠀⢠⣿⣿⡏⢿⣯⣭⠷⣭⣭⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣃⣿⣿⣯⣟⣯⡿⣽⣻⢞⡵
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠱⡈⠹⡄⠀⠀⠀⠀⠀⠀⠀⠈⠙⠋⣙⣹⣿⣿⡿⠋⠀⠀⠀⠀⢺⣿⣿⣿⣆⢻⣿⣻⣶⣷⣿⣿⣿⡿⣟⣿⣿⣿⣿⣿⣿⣿⣟⣾⢯⡿⣽⡷⣯⢿⣹
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡀⠀⢲⡾⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠜⡹⠟⠉⠀⣀⠀⠀⠀⠀⠘⣿⣿⣿⣿⣞⡽⢿⣿⡿⢿⡟⢶⣡⣿⣿⣿⣿⣿⣿⣿⣳⣯⢿⣯⣟⣷⣻⣽⡳⣏
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⡀⣀⡆⠀⠀⠀⠀⠀⠠⠀⠀⠀⠀⠀⢀⣠⣾⣿⠀⠀⠀⠀⢠⣿⣿⣿⣿⡏⠱⠂⠄⣙⢣⣟⣮⣿⣿⣿⣿⣿⣿⣿⣟⣷⣻⣟⡾⣽⣞⡷⣯⡽⣳
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⠏⠀⠀⠀⠀⢈⣿⣿⣿⣿⣍⠣⡉⠴⣌⢷⣾⣻⣿⣿⣿⣿⣿⣿⡿⣞⣯⢷⣯⡟⣷⣫⡽⢶⡻⣵
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠈⡑⢺⡿⢏⢀⣠⣀⠀⣦⣀⢻⣿⣿⣿⣿⣣⣝⡳⣎⣿⣽⣿⣿⣿⣿⣿⣿⣟⣿⡽⣯⣟⢶⡻⣵⢣⡟⣯⢳⢧
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠟⠁⢰⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⣟⢢⣏⣷⢿⣭⣻⢷⣿⣿⣿⣿⣽⣾⣳⣟⣷⣫⢯⡷⣭⢳⡝⣮⢛⡼
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠷⣞⡿⣎⡶⣿⣿⣿⣿⣿⣿⣞⡷⣟⣾⡳⣏⡷⣹⢎⡷⣙⢦⣋⠖
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣺⣽⢳⢏⣾⣿⣿⣿⡍⣉⣛⣻⡿⢿⣾⣽⣝⣳⣝⢮⠳⣍⠶⣉⠞
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠁⠀⣧⠀⠀⠀⠀⠀⠀⠀⣠⣶⣿⡿⠿⠾⠿⠿⠿⠿⠿⣿⣿⣿⣿⣿⣿⣞⢿⣺⣿⣿⣿⣿⣿⡉⢿⣿⡙⠲⣤⣈⡙⠻⠮⣽⣙⡌⢣⠱⣊
- ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠀⠀⢸⣆⠠⡀⠀⠀⠀⠀⠘⠉⠁⠀⠀⢀⣠⣶⣿⢿⡛⣴⣿⣻⢻⡽⣷⢯⣞⣿⣿⣷⣿⣿⣿⣿⣿⣿⡁⠀⠀⢢⠉⠱⣄⠀⠉⠈⠐⠃⠄
- ⣿⣿⣿⣿⢿⣻⣿⣿⣿⣿⡿⠋⠀⠀⠀⠀⢀⠹⣄⠙⣄⡀⠀⠀⠜⢢⠳⣾⣿⣿⣿⣿⣿⣷⣯⡷⢭⡷⣯⢿⣯⣿⢾⣯⣿⣿⣿⣿⣿⣿⣿⣿⣷⣆⠀⠀⠉⠢⠈⢦⡀⠀⠀⠀⠀
- ⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⠀⠀⠀⠀⠀⠀⠀⢱⡙⢧⡈⠻⣦⣄⠘⠀⠠⠀⠈⠁⠀⠀⠀⠀⠀⢌⢧⡻⡽⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⣷⡄⠀⠀⠃⠈⣷⡀⠀⠀⠀
- ⣿⣿⣧⣿⣿⣧⣿⠟⠀⠀⠀⣠⠀⠀⢀⣠⠀⠀⢿⠛⠻⢤⡘⠻⣤⡀⠀⠀⠀⠀⢀⣀⣠⣤⡼⣼⢧⣿⣻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣸⣿⡄⠀⠀⢀⠸⡇⠀⠀⠀
- ⣿⣷⡿⣿⣽⠟⠁⠀⣠⡏⢰⡇⠀⠀⢸⣿⠀⠀⠘⣧⠤⠄⠙⢶⣌⠛⢶⣤⣶⣶⣿⣾⣿⣯⣟⣯⣿⢷⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣿⣿⣿⣿⣿⣿⣳⢯⣿⡄⠘⠤⢂⠙⢦⡀⠀
- ⣟⡾⣽⠟⠁⠀⠀⢠⡿⠀⣾⡇⠀⠀⠹⢿⣀⣤⡀⠙⢆⡰⣳⣦⣈⡛⣶⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣟⣿⣿⣿⣿⣿⣿⣷⢫⣞⢿⡃⠄⢂⠀⢣⢳⡀
- ⣯⡟⠃⠀⡰⠀⠀⣿⠃⢸⣿⡇⢀⠀⡀⠀⠈⠻⢿⣷⣮⠵⣹⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣻⣷⣿⣿⣟⡿⣷⣿⠮⣝⡷⣎⠲⣅⠀⠀⠈⠀⠡⢓
- ⠋⠀⣀⠔⠁⠀⢀⡇⠀⣾⣿⡄⠈⣆⠘⡀⠀⠀⠀⠹⢿⣿⣿⣟⣯⣙⣌⣙⡻⢿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⡿⣿⢯⣟⣿⣿⡿⣿⡽⣾⣽⣻⣿⡹⣌⢳⣍⡒⠈⠄⠀⠀⠀⠀⠈
- ⠀⠀⠀⠠⣆⠀⢸⠀⢠⠿⣿⡇⠀⢸⣧⠑⢦⠀⠁⠀⠀⢈⠛⢿⣿⣽⣶⣯⣽⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣯⣿⣻⣞⡷⣿⢯⣟⣷⢳⣿⣯⡕⢎⠲⡡⠌⠐⠠⡀⠀⢀⠀⠀
- ⠀⠀⠀⠀⠈⢆⡇⠠⠊⠀⣿⡇⠀⠀⣿⡷⣄⠳⣤⠀⢠⠀⠀⠀⠘⠻⠿⣿⢿⡿⠟⢉⡟⣿⣿⣿⣿⣿⣿⣿⣿⣿⢷⣟⣾⢿⣽⡻⢾⡭⣟⣿⡗⢮⡡⠂⠑⣂⠀⡲⢱⠀⠄⡁⠀
- ⠀⠀⠀⠀⠀⠀⠱⡄⠀⠀⣿⣷⠀⠀⢸⡷⠜⢧⡈⠂⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣿⡾⡽⢧⠿⣜⣿⡟⢢⠑⡤⠘⢤⠣⢌⢣⠘⠠⠀⠂
- ⣾⣦⡀⠀⠀⠀⠀⢙⣦⠀⣿⣿⠀⠀⠀⠀⠆⠐⠛⣦⣄⠠⣄⠀⠰⠀⠀⠀⠀⠀⡐⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡷⢯⡿⣷⣿⣻⠯⣷⣎⡿⡍⢦⡙⠴⡁⠎⣇⠫⢄⠊⢀⠁⠀
- ⠀⠀⠉⠲⣭⣯⣿⣾⣿⣷⣽⣿⡀⠀⠀⠀⠁⠀⣨⡇⠸⣷⣄⠁⠄⠀⠀⠀⠀⠀⢠⣿⣿⣿⡿⣟⢿⣿⣿⣿⣿⣿⣿⡣⢿⡱⢎⡝⠻⠶⣾⡽⣙⠦⡙⠤⠃⢘⠀⢳⡈⡐⠀⠀⠀
- ⠀⠀⠀⠀⡿⢿⣿⣿⣿⣿⣿⣿⣇⢠⠐⡁⢰⣿⠿⡷⠀⠹⡙⣶⣄⡀⠀⢠⡄⢀⣾⡿⣟⢣⠟⡼⢫⣿⢿⣿⣿⣿⡿⣿⣷⣏⠂⢜⡱⣌⡄⢣⣝⠂⡉⠒⡁⠀⠀⠂⠐⠈⠀⠠⠀
- */
Advertisement
Add Comment
Please, Sign In to add comment