Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- void cvb(vector <bool> v){
- for (bool x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvs(vector <string> v){
- for (auto a: v){
- cout<<a<<"\n";
- }
- }
- void cvp(vector <pii> a){
- for (auto p: a){
- cout<<p.first<<' '<<p.second<<"\n";
- }
- cout<<"\n";
- }
- bool sh=0;
- ll p=101, mod = 1e9+7;
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- string s; cin>>s;
- int n = s.size();
- vector <ll> pf(n), repf(n), powp(n,1);
- pf[0] = s[0] - 'a' + 1;
- repf[n - 1] = s[n - 1] - 'a' + 1;
- for (int i = 1; i < n; ++i){
- powp[i] = powp[i - 1] * p % mod;
- }
- for (int i = 1; i < n; ++i){
- pf[i] = pf[i - 1] + (s[i] - 'a' + 1) * powp[i];
- pf[i] %= mod;
- }
- for (int i = n - 2; i >= 0; --i){
- repf[i] = repf[i + 1] + (s[i] - 'a' + 1) * powp[ n - 1- i];
- repf[i] %= mod;
- }
- if (sh){
- cout<<"pf\n"; cvl(pf);
- cout<<"repf\n"; cvl(repf);
- }
- vector <int> ans(n);
- if (sh){
- cout<<"ODD\n";
- }
- //считаем бинопоиском нечетные
- for (int i = 0; i < n; ++i){
- if (sh){
- cout<<"i = "<<i<<"\n";
- }
- int mxl = min(i + 1, n - i); //длина макс
- int L = 1, R = mxl + 1, M;//L-ans
- if (sh){
- cout<<"L R = "<<L<<' '<<R<<"\n";
- }
- ll del = 0, redel=0;
- if (i > 0) del = pf[i - 1];
- if (i < n - 1) redel = repf[i + 1];
- while (L + 1 < R){
- M = (L + R) / 2;
- ll A = (pf[i + M - 1] - del + mod) % mod * powp[n - 1 - (i + M - 1)] % mod;
- ll B = (repf[i - M + 1] - redel + mod) % mod * powp[i - M + 1] % mod;
- if (sh){
- cout<<"A B = "<<A<<' '<<B<<"\n";
- }
- if (A == B)
- {
- L = M;
- }
- else{
- R = M;
- }
- }
- if (sh){
- cout<<"L = "<<' '<<L<<"\n";
- }
- ans[i] = 2*L - 1;
- }
- if (sh){
- cout<<"\nEVEN\n";
- }
- /*for (int i = 0; i < n - 1; ++i){
- if (sh){
- cout<<"i = "<<i<<"\n";
- }
- if (s[i] != s[i+1]) continue;
- int mxl = min(i+1, n - i - 1);
- ll del = pf[i], redel = repf[i + 1];
- int L = 1, R = mxl + 1, M;
- if (sh){
- cout<<"L R = "<<L<<' '<<R<<"\n";
- }
- while (L + 1 < R){
- M = (L + R) / 2;
- ll A = ( pf[ i + M ] - del + mod) % mod * powp[n - 1 - (i + M)] % mod;
- ll B = ( repf[i - M + 1] - redel + mod) % mod * powp[i - M + 1] % mod;
- if (A == B){
- L = M;
- }
- else{
- R = M;
- }
- }
- if (sh){
- cout<<"L = "<<' '<<L<<"\n";
- }
- ans[i] = max(ans[i], 2*L);
- ans[i + 1] = max(ans[i + 1], 2*L);
- }*/
- cv(ans);
- }
- /*
- aaa ошибка
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement