Description
Input
Output
Sample Input
Sample Output
HINT
Source
Bzoj Untitled face 233
Anyway online a bunch of myself download BA >_<
Build Sam on crossdress and then DP
The first question is exactly the same as the AHOI2013 difference.
Specific solution:
Set Ans1[i] as the suffix logarithm of LCP exactly I, ans2[i] is the maximum value product of the suffix of LCP exactly I
After the SAM is built, record the number of suffixes in the subtree, the value of the maximum value, the value of the minimum value, and then O (n) DP can
In Sam, I remember the last statistic to Ans1 and Ans2.
Size will explode int ... The opening int has been Wawawawa ...
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#define MAXN 600100#define LL Long Long#define MAXINT 1ll<<60using namespace STD;intN,top; LL A[MAXN];CharCH[MAXN]; LL ANS1[MAXN],ANS2[MAXN];structedge{intto; Edge *next;} e[maxn<<1],*PREV[MAXN];voidInsertintUintV) {E[++top].to=v;e[top].next=prev[u];p rev[u]=&e[top];}voidIn (LL &x) {CharCh=getchar (); x=0;intflag=1; while(! (ch>=' 0 '&&ch<=' 9 ')) flag=ch=='-'?-1:1, Ch=getchar (); while(ch>=' 0 '&&ch<=' 9 ') x=x*Ten+ch-' 0 ', Ch=getchar (); x*=flag;}structsam{intCNT,LAST,P,Q,NP,NQ;inta[maxn][ -],LEN[MAXN],FA[MAXN]; LL MAXN[MAXN],MINN[MAXN],ANS1[MAXN],ANS2[MAXN],SIZE[MAXN]; Sam () {last=++cnt; }voidInsertintCintx) {p=last;last=np=++cnt;len[np]=len[p]+1; size[np]=1; maxn[np]=minn[np]=a[x]; while(!a[p][c]&&p) a[p][c]=np,p=fa[p];if(!p) fa[np]=1;Else{Q=a[p][c];if(len[q]==len[p]+1) fa[np]=q;Else{nq=++cnt;len[nq]=len[p]+1; maxn[cnt]=-maxint;minn[cnt]=maxint;memcpy(A[nq],a[q],sizeof(A[q])); FA[NQ]=FA[Q];FA[Q]=FA[NP]=NQ; while(a[p][c]==q) a[p][c]=nq,p=fa[p]; }}}}sam;voidDfsintx) { for(Edge *i=prev[x];i;i=i->next) {DFS (i->to); sam.ans1[x]+=sam.size[x]*sam.size[i->to]; sam.size[x]+=sam.size[i->to];if(sam.maxn[x]!=-maxint) Sam.ans2[x]=max (sam.ans2[x],sam.maxn[i->to]*sam.maxn[x]);if(sam.minn[x]!=maxint) Sam.ans2[x]=max (sam.ans2[x],sam.minn[i->to]*sam.minn[x]); Sam.maxn[x]=max (Sam.maxn[x],sam.maxn[i->to]); Sam.minn[x]=min (Sam.minn[x],sam.minn[i->to]); }}intMain () {Freopen ("Savour.in","R", stdin); Freopen ("Savour.out","W", stdout);scanf("%d", &n);scanf('%s ', ch); sam.maxn[1]=-maxint;sam.minn[1]=maxint; for(intI=1; i<=n;i++) in (A[i]); for(inti=n;i;i--) Sam.insert (ch[i-1]-' A ', i); for(intI=0; i<=sam.cnt;i++) Sam.ans2[i]=-maxint; for(intI=1; i<=sam.cnt;i++) insert (sam.fa[i],i); Dfs1); for(intI=0; i<n;i++) Ans2[i]=-maxint; for(intI=1; i<=sam.cnt;i++) Ans1[sam.len[i]]+=sam.ans1[i],ans2[sam.len[i]]=max (Ans2[sam.len[i]],sam.ans2[i]); for(inti=n-2; i>=0; i--) {ans1[i]+=ans1[i+1];if(ans1[i+1]) Ans2[i]=max (ans2[i],ans2[i+1]); } for(intI=0; i<n;i++)printf("%lld%lld\n", Ans1[i],ans1[i]? Ans2[i]:0);}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"NOI2015" "BZOJ4199" wine Tasting Conference