#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<map> using namespace std; #define N 300000 #define LL long long int n,x,cnt,p,np,q,nq,stt[N],fa[N]; LL ans; map<int,int> c[N]; void extend(int w){ p=np; stt[np=++cnt]=stt[p]+1; for (;p && !c[p].count(w);p=fa[p]) c[p][w]=np; if (!p) fa[np]=1; else{ if (stt[q=c[p][w]]==stt[p]+1) fa[np]=q; else{ stt[nq=++cnt]=stt[p]+1; for (map<int,int>::iterator i=c[q].begin();i!=c[q].end();i++) c[nq][i->first]=i->second; fa[nq]=fa[q]; fa[q]=fa[np]=nq; for (;p && c[p][w]==q;p=fa[p]) c[p][w]=nq; } } } int main(){ scanf("%d",&n); cnt=np=1; for (int i=1;i<=n;i++){ scanf("%d",&x); extend(x); ans+=stt[np]-stt[fa[np]]; printf("%lld\n",ans); } }
|