Advertisement
Korotkodul

ХЭШИ F WA

Sep 19th, 2022 (edited)
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. #define vec vector
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v){
  17.     for (auto x: v) cout<<x<<' ';
  18.     cout<<"\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v){
  22.     for (auto x: v) cout<<x<<' ';
  23.     cout<<"\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v){
  28.     for (auto x: v) cv(x);
  29.     cout<<"\n";
  30. }
  31.  
  32. void cvb(vector <bool> v){
  33.     for (bool x: v) cout<<x<<' ';
  34.     cout<<"\n";
  35. }
  36.  
  37. void cvs(vector <string>  v){
  38.     for (auto a: v){
  39.         cout<<a<<"\n";
  40.     }
  41. }
  42.  
  43. void cvp(vector <pii> a){
  44.     for (auto p: a){
  45.         cout<<p.first<<' '<<p.second<<"\n";
  46.     }
  47.     cout<<"\n";
  48. }
  49.  
  50. bool sh=0;
  51.  
  52. ll p=101, mod = 1e9+7;
  53.  
  54. int main()
  55. {
  56.     ios::sync_with_stdio(0);
  57.     cin.tie(0);
  58.     cout.tie(0);
  59.     string s; cin>>s;
  60.     int n = s.size();
  61.     vector <ll> pf(n), repf(n), powp(n,1);
  62.     pf[0] = s[0] - 'a' + 1;
  63.     repf[n - 1] = s[n - 1] - 'a' + 1;
  64.     for (int i = 1; i < n; ++i){
  65.         powp[i] = powp[i - 1] * p % mod;
  66.     }
  67.     for (int i = 1; i < n; ++i){
  68.         pf[i] = pf[i - 1] + (s[i] - 'a' + 1) * powp[i];
  69.         pf[i] %= mod;
  70.     }
  71.     for (int i = n - 2; i >= 0; --i){
  72.         repf[i] = repf[i + 1] + (s[i] - 'a' + 1) * powp[ n - 1- i];
  73.         repf[i] %= mod;
  74.     }
  75.     if (sh){
  76.         cout<<"pf\n"; cvl(pf);
  77.         cout<<"repf\n"; cvl(repf);
  78.     }
  79.     vector <int> ans(n);
  80.     if (sh){
  81.         cout<<"ODD\n";
  82.     }
  83.     //считаем бинопоиском нечетные
  84.     for (int i = 0; i < n; ++i){
  85.         if (sh){
  86.             cout<<"i = "<<i<<"\n";
  87.         }
  88.         int mxl = min(i + 1, n - i); //длина макс
  89.         int L = 1, R = mxl + 1, M;//L-ans
  90.         if (sh){
  91.             cout<<"L R = "<<L<<' '<<R<<"\n";
  92.         }
  93.         ll del = 0, redel=0;
  94.         if (i > 0) del = pf[i - 1];
  95.         if (i < n - 1) redel = repf[i + 1];
  96.         while (L + 1 < R){
  97.             M = (L + R) / 2;
  98.             ll A = (pf[i + M - 1] -  del + mod) % mod * powp[n - 1 - (i + M - 1)] % mod;
  99.             ll B = (repf[i - M + 1] - redel + mod) % mod * powp[i - M + 1] % mod;
  100.             if (sh){
  101.                 cout<<"A B = "<<A<<' '<<B<<"\n";
  102.             }
  103.             if (A  == B)
  104.             {
  105.                 L = M;
  106.             }
  107.             else{
  108.                 R = M;
  109.             }
  110.         }
  111.         if (sh){
  112.             cout<<"L = "<<' '<<L<<"\n";
  113.         }
  114.         ans[i] = 2*L - 1;
  115.     }
  116.  
  117.     if (sh){
  118.         cout<<"\nEVEN\n";
  119.     }
  120.     /*for (int i = 0; i < n - 1; ++i){
  121.         if (sh){
  122.             cout<<"i = "<<i<<"\n";
  123.         }
  124.         if (s[i] != s[i+1]) continue;
  125.         int mxl = min(i+1, n - i - 1);
  126.         ll del = pf[i], redel = repf[i + 1];
  127.         int L = 1, R = mxl + 1, M;
  128.         if (sh){
  129.             cout<<"L R = "<<L<<' '<<R<<"\n";
  130.         }
  131.         while (L + 1 < R){
  132.             M = (L + R) / 2;
  133.             ll A = ( pf[ i + M ] - del + mod) % mod * powp[n - 1 - (i +  M)] % mod;
  134.             ll B = ( repf[i - M + 1] - redel + mod) % mod * powp[i - M + 1] % mod;
  135.             if (A == B){
  136.                 L = M;
  137.             }
  138.             else{
  139.                 R = M;
  140.             }
  141.         }
  142.         if (sh){
  143.             cout<<"L = "<<' '<<L<<"\n";
  144.         }
  145.         ans[i] = max(ans[i], 2*L);
  146.         ans[i + 1] = max(ans[i + 1], 2*L);
  147.     }*/
  148.  
  149.     cv(ans);
  150. }
  151. /*
  152. aaa ошибка
  153. */
  154.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement