由于
串是不增的
可以发现一定连续一段
串相同
于是考虑先分割成单减的,然后每一部分按循环节分割
考虑假设已经求出了
的
分解且恰好分解完
考虑从
开始,设
两指针,初始
指向循环节
的结尾,
若
即可
若
,那么
之后单独一定更优,而前面是
长度的循环节
若
重新形成了循环节
复杂度
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define y1 shinkle
#define fi first
#define se second
#define bg begin
cs int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob)?EOF:*ib++;
}
inline int read(){
char ch=gc();
int res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
inline ll readll(){
char ch=gc();
ll res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
inline int readstring(char *s){
int top=0;char ch=gc();
while(isspace(ch))ch=gc();
while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
s[top+1]='\0';return top;
}
template<typename tp>inline void chemx(tp &a,tp b){a=max(a,b);}
template<typename tp>inline void chemn(tp &a,tp b){a=min(a,b);}
cs int N=(1<<20)|1;
char s[N];
int n;
int main(){
#ifdef Stargazer
freopen("lx.in","r",stdin);
#endif
n=readstring(s);
for(int i=1,j,k;i<=n;){
j=i,k=i+1;
while(s[j]<=s[k]){
if(s[j]==s[k])j++,k++;
else j=i,k++;
}
while(i<=j){
cout<<i+k-j-1<<" ";
i+=k-j;
}
}
}