Salvens

Untitled

Jul 24th, 2023
1,088
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.07 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cmath>
  5. #include <vector>
  6. #include <set>
  7. #include <map>
  8. #include <string>
  9. #include <cassert>
  10. #include <numeric>
  11. #include <queue>
  12. #include <cstdint>
  13. #include <string>
  14. #include <unordered_map>
  15. #include <unordered_set>
  16. #include <stack>
  17.  
  18. using namespace std;
  19.  
  20. #define int long long
  21. #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  22.  
  23. const long long INF = 1e18 + 7;
  24. const double EPS = 1e-9;
  25. const int MOD = 1e9 + 7;
  26. const int N = 2e3 + 10;
  27. const int K = 64;
  28. const int B = 500;
  29.  
  30. inline void solve() {
  31.     string s;
  32.     cin >> s;
  33.     int n = s.size();
  34.     vector<int> z(n, 0);
  35.     int l = 0, r = 0;
  36.     for (int i = 1; i < n; ++i) {
  37.         if (r >= i) {
  38.             z[i] = min(z[i - l], r - i + 1);
  39.         }
  40.         while (z[i] + i < n && s[z[i] + i] == s[z[i]]) {
  41.             ++z[i];
  42.         }
  43.         if (r < i + z[i] - 1) {
  44.             l = i;
  45.             r = i + z[i] - 1;
  46.         }
  47.     }
  48.     for (int i = 1; i < n; ++i) {
  49.         cout << z[i] << ' ';
  50.     }
  51. }
  52.  
  53.  
  54. int32_t main() {
  55.     IOS;
  56.  
  57. //    freopen("knight.in", "r", stdin);
  58. //    freopen("knight.out", "w", stdout);
  59.  
  60.  
  61.     int tt = 1;
  62. //    cin >> tt;
  63.     while (tt--) {
  64.         solve();
  65.     }
  66.     return 0;
  67. }
  68.  
  69. /*
  70. 1.  数组开够了没
  71. 2.  文件名写对了没,文件夹建了吗
  72. 3.  内存会不会MLE
  73. 4.  多测清空?
  74. 5.  调试删干净了没
  75. 6.  取模有没有溢出
  76. 7.  快速幂底数要取模,幂对 mod-1 取模
  77. 8.  前向星和欧拉序要开2倍数组
  78. 9.  比较函数如果值相同的话有没有第二优先级
  79. 10. 线段树 4 倍空间,线段树合并和可持久化线段树 32 倍空间
  80. 11. 看清楚 log 的底数是啥,log后面的数是啥
  81. 12. long long 只有正负 2^63-1
  82. */
  83.  
  84.  
  85.  
  86. /*
  87. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠿⠿⠻⠟⢛⣛⡿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣳
  88. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣋⣉⡄⠀⣀⡀⠨⣙⣏⣉⣽⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⣿⡿⣿⢿⣿⣿⣿⡿⣟⣿⣯⣿⣷⣿⢾⣿
  89. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⣛⣒⡛⢫⠤⣠⢤⣤⣤⣹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣻⣯⣿⢿⣿⢯⣿⣯⣿⣿⣻⣞⡷⣿⣽⣻⡽
  90. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢮⣭⣉⡓⠺⠊⢉⠓⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡽⣿⣻⢿⡿⣯⢿⣷⢯⡷⣯⣟⠷⣯⡗⡿
  91. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⣩⣿⣿⢿⣷⣄⡙⢮⠭⡁⢠⣬⣿⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣽⣯⢿⣽⡿⣾⣻⣽⣳⣞⣟⡧⣟⡽
  92. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⠀⡴⠹⢿⣿⣀⣿⣿⣯⣍⢛⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⣾⡿⣯⣿⡽⣟⡾⣵⢫⣾⡱⢯⡜
  93. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠁⢀⣞⣰⣀⣾⡷⠘⣿⣿⣟⣩⠙⠛⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣻⢷⣟⣿⢯⡷⣏⡟⣶⡹⢇⡞
  94. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠁⣰⢯⣾⣿⣿⡿⠁⠀⠀⠼⢿⣿⠥⢤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣽⣟⡾⣟⣯⢿⡼⣹⢶⡹⢣⠞
  95. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⣴⣿⣿⣿⣿⠟⠀⠀⠀⠀⠀⠀⠘⠺⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⢿⡽⣯⣟⢾⡱⣏⠵⣋⠎
  96. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠻⢬⡙⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣽⣳⢯⣏⡗⣎⠳⡌⠆
  97. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠙⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⣷⢻⡗⣮⡝⣬⢳⠉⡎
  98. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⡿⣯⢷⣫⢗⡭⢎⢧⡙
  99. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣿⣿⣿⣶⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢡⣀⢛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣟⣯⣟⣧⡟⡼⣉⢆⠣
  100. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠹⣿⢿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠤⡂⠭⢊⠻⡹⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⣷⣻⣞⡽⣲⢍⡎⢇
  101. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡀⢻⠆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⢡⠒⠐⢀⠀⠠⠐⡆⢯⡹⡹⢛⡯⢭⡹⣿⣿⣿⣿⣿⣿⣿⡿⣾⢯⣷⣻⣜⡳⢎⡜⠦
  102. ⣿⣿⣿⣿⣿⣿⣿⣿⠟⠛⠻⢷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⠀⠀⠀⠀⠀⠀⠀⡄⠠⢎⢦⡹⢄⡄⣌⣩⣝⠾⣡⢃⠡⠃⡘⢧⠿⣽⣻⣿⣿⣿⣿⣿⣽⣿⣟⣷⣻⡼⣝⢮⡙⡖
  103. ⣿⣿⣿⣿⣿⣿⣿⠃⣾⣷⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢉⣩⣁⣳⣶⣦⣤⣤⣈⣥⢛⡞⣶⣿⣜⣫⢝⣶⣫⢞⣡⣀⣒⣀⡴⣨⡽⣎⣿⣿⣿⣿⣿⣿⣿⣿⢾⣯⢷⣻⡜⣮⢱⢣
  104. ⣿⣿⣿⣿⣿⣿⣿⡇⣿⢻⠇⠛⢧⠀⠀⠀⠀⠀⠀⠾⠛⣉⣭⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢟⣿⣯⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣯⣿⢾⣯⢷⣻⣼⢣⢧
  105. ⣿⣿⣿⣿⣿⣿⣿⣿⡌⣿⠀⣶⣿⠃⠀⠀⠀⠀⢰⣶⡾⠟⠫⣈⢿⡿⠟⣨⣿⣿⣿⢿⡆⠀⠈⣿⣿⣿⣿⣿⡟⢹⣯⣿⡟⢻⣿⣿⣿⣿⣿⣿⣿⣿⡏⢸⣿⢯⣿⢯⡿⣟⡾⣏⣞
  106. ⣿⣿⣿⣿⣿⣿⣿⣿⣷⠸⡀⢿⡃⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣉⣛⠶⣿⣿⣿⣿⠟⣿⠃⠀⢠⣿⣿⡏⢿⣯⣭⠷⣭⣭⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣃⣿⣿⣯⣟⣯⡿⣽⣻⢞⡵
  107. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠱⡈⠹⡄⠀⠀⠀⠀⠀⠀⠀⠈⠙⠋⣙⣹⣿⣿⡿⠋⠀⠀⠀⠀⢺⣿⣿⣿⣆⢻⣿⣻⣶⣷⣿⣿⣿⡿⣟⣿⣿⣿⣿⣿⣿⣿⣟⣾⢯⡿⣽⡷⣯⢿⣹
  108. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡀⠀⢲⡾⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠜⡹⠟⠉⠀⣀⠀⠀⠀⠀⠘⣿⣿⣿⣿⣞⡽⢿⣿⡿⢿⡟⢶⣡⣿⣿⣿⣿⣿⣿⣿⣳⣯⢿⣯⣟⣷⣻⣽⡳⣏
  109. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⡀⣀⡆⠀⠀⠀⠀⠀⠠⠀⠀⠀⠀⠀⢀⣠⣾⣿⠀⠀⠀⠀⢠⣿⣿⣿⣿⡏⠱⠂⠄⣙⢣⣟⣮⣿⣿⣿⣿⣿⣿⣿⣟⣷⣻⣟⡾⣽⣞⡷⣯⡽⣳
  110. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⠏⠀⠀⠀⠀⢈⣿⣿⣿⣿⣍⠣⡉⠴⣌⢷⣾⣻⣿⣿⣿⣿⣿⣿⡿⣞⣯⢷⣯⡟⣷⣫⡽⢶⡻⣵
  111. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠈⡑⢺⡿⢏⢀⣠⣀⠀⣦⣀⢻⣿⣿⣿⣿⣣⣝⡳⣎⣿⣽⣿⣿⣿⣿⣿⣿⣟⣿⡽⣯⣟⢶⡻⣵⢣⡟⣯⢳⢧
  112. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠟⠁⢰⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⣟⢢⣏⣷⢿⣭⣻⢷⣿⣿⣿⣿⣽⣾⣳⣟⣷⣫⢯⡷⣭⢳⡝⣮⢛⡼
  113. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠷⣞⡿⣎⡶⣿⣿⣿⣿⣿⣿⣞⡷⣟⣾⡳⣏⡷⣹⢎⡷⣙⢦⣋⠖
  114. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣺⣽⢳⢏⣾⣿⣿⣿⡍⣉⣛⣻⡿⢿⣾⣽⣝⣳⣝⢮⠳⣍⠶⣉⠞
  115. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠁⠀⣧⠀⠀⠀⠀⠀⠀⠀⣠⣶⣿⡿⠿⠾⠿⠿⠿⠿⠿⣿⣿⣿⣿⣿⣿⣞⢿⣺⣿⣿⣿⣿⣿⡉⢿⣿⡙⠲⣤⣈⡙⠻⠮⣽⣙⡌⢣⠱⣊
  116. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠀⠀⢸⣆⠠⡀⠀⠀⠀⠀⠘⠉⠁⠀⠀⢀⣠⣶⣿⢿⡛⣴⣿⣻⢻⡽⣷⢯⣞⣿⣿⣷⣿⣿⣿⣿⣿⣿⡁⠀⠀⢢⠉⠱⣄⠀⠉⠈⠐⠃⠄
  117. ⣿⣿⣿⣿⢿⣻⣿⣿⣿⣿⡿⠋⠀⠀⠀⠀⢀⠹⣄⠙⣄⡀⠀⠀⠜⢢⠳⣾⣿⣿⣿⣿⣿⣷⣯⡷⢭⡷⣯⢿⣯⣿⢾⣯⣿⣿⣿⣿⣿⣿⣿⣿⣷⣆⠀⠀⠉⠢⠈⢦⡀⠀⠀⠀⠀
  118. ⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⠀⠀⠀⠀⠀⠀⠀⢱⡙⢧⡈⠻⣦⣄⠘⠀⠠⠀⠈⠁⠀⠀⠀⠀⠀⢌⢧⡻⡽⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⣷⡄⠀⠀⠃⠈⣷⡀⠀⠀⠀
  119. ⣿⣿⣧⣿⣿⣧⣿⠟⠀⠀⠀⣠⠀⠀⢀⣠⠀⠀⢿⠛⠻⢤⡘⠻⣤⡀⠀⠀⠀⠀⢀⣀⣠⣤⡼⣼⢧⣿⣻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣸⣿⡄⠀⠀⢀⠸⡇⠀⠀⠀
  120. ⣿⣷⡿⣿⣽⠟⠁⠀⣠⡏⢰⡇⠀⠀⢸⣿⠀⠀⠘⣧⠤⠄⠙⢶⣌⠛⢶⣤⣶⣶⣿⣾⣿⣯⣟⣯⣿⢷⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣿⣿⣿⣿⣿⣿⣳⢯⣿⡄⠘⠤⢂⠙⢦⡀⠀
  121. ⣟⡾⣽⠟⠁⠀⠀⢠⡿⠀⣾⡇⠀⠀⠹⢿⣀⣤⡀⠙⢆⡰⣳⣦⣈⡛⣶⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣟⣿⣿⣿⣿⣿⣿⣷⢫⣞⢿⡃⠄⢂⠀⢣⢳⡀
  122. ⣯⡟⠃⠀⡰⠀⠀⣿⠃⢸⣿⡇⢀⠀⡀⠀⠈⠻⢿⣷⣮⠵⣹⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣻⣷⣿⣿⣟⡿⣷⣿⠮⣝⡷⣎⠲⣅⠀⠀⠈⠀⠡⢓
  123. ⠋⠀⣀⠔⠁⠀⢀⡇⠀⣾⣿⡄⠈⣆⠘⡀⠀⠀⠀⠹⢿⣿⣿⣟⣯⣙⣌⣙⡻⢿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⡿⣿⢯⣟⣿⣿⡿⣿⡽⣾⣽⣻⣿⡹⣌⢳⣍⡒⠈⠄⠀⠀⠀⠀⠈
  124. ⠀⠀⠀⠠⣆⠀⢸⠀⢠⠿⣿⡇⠀⢸⣧⠑⢦⠀⠁⠀⠀⢈⠛⢿⣿⣽⣶⣯⣽⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣯⣿⣻⣞⡷⣿⢯⣟⣷⢳⣿⣯⡕⢎⠲⡡⠌⠐⠠⡀⠀⢀⠀⠀
  125. ⠀⠀⠀⠀⠈⢆⡇⠠⠊⠀⣿⡇⠀⠀⣿⡷⣄⠳⣤⠀⢠⠀⠀⠀⠘⠻⠿⣿⢿⡿⠟⢉⡟⣿⣿⣿⣿⣿⣿⣿⣿⣿⢷⣟⣾⢿⣽⡻⢾⡭⣟⣿⡗⢮⡡⠂⠑⣂⠀⡲⢱⠀⠄⡁⠀
  126. ⠀⠀⠀⠀⠀⠀⠱⡄⠀⠀⣿⣷⠀⠀⢸⡷⠜⢧⡈⠂⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣿⡾⡽⢧⠿⣜⣿⡟⢢⠑⡤⠘⢤⠣⢌⢣⠘⠠⠀⠂
  127. ⣾⣦⡀⠀⠀⠀⠀⢙⣦⠀⣿⣿⠀⠀⠀⠀⠆⠐⠛⣦⣄⠠⣄⠀⠰⠀⠀⠀⠀⠀⡐⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡷⢯⡿⣷⣿⣻⠯⣷⣎⡿⡍⢦⡙⠴⡁⠎⣇⠫⢄⠊⢀⠁⠀
  128. ⠀⠀⠉⠲⣭⣯⣿⣾⣿⣷⣽⣿⡀⠀⠀⠀⠁⠀⣨⡇⠸⣷⣄⠁⠄⠀⠀⠀⠀⠀⢠⣿⣿⣿⡿⣟⢿⣿⣿⣿⣿⣿⣿⡣⢿⡱⢎⡝⠻⠶⣾⡽⣙⠦⡙⠤⠃⢘⠀⢳⡈⡐⠀⠀⠀
  129. ⠀⠀⠀⠀⡿⢿⣿⣿⣿⣿⣿⣿⣇⢠⠐⡁⢰⣿⠿⡷⠀⠹⡙⣶⣄⡀⠀⢠⡄⢀⣾⡿⣟⢣⠟⡼⢫⣿⢿⣿⣿⣿⡿⣿⣷⣏⠂⢜⡱⣌⡄⢣⣝⠂⡉⠒⡁⠀⠀⠂⠐⠈⠀⠠⠀
  130. */
  131.  
Advertisement
Add Comment
Please, Sign In to add comment