BZOJ3172 suffix Array

Source: Internet
Author: User

Test instructions: Find out the number of occurrences of each word in an article

The sample does not understand = =, why the number of AAA is 1, but the number of AA is 3 ah ...

The standard solution seems to be an AC automaton or suffix automaton, and someone with kmp violent = =

With a suffix array. Originally did not brush this type, by the way review ~

Reference:http://blog.sina.com.cn/s/blog_6e63f59e0101bpw5.html

Take a sample example:

For the height of the first letter of each word, the number of height above and below the height value is greater than or equal to the word length.

Attention to detail processing = =

1 //BT5 under the attack when the value of the increase (more than 2000) on the line, in particular, you can see the Internet Hack wireless network password article, that is, after the capture packet, the command to inject the packet2#include"iostream"3#include"CString"4 using namespacestd;5 #defineMAXN 10100006 7 intWA[MAXN],WB[MAXN],WV[MAXN],WWS[MAXN];8 intRANK[MAXN],HEIGHT[MAXN];9 intR[MAXN],SA[MAXN],ANS[MAXN],ST[MAXN],LN[MAXN];Ten intN,len,tl; One CharTS[MAXN]; A  - intcmpint*r,intAintBintl) - { the     returnr[a]==r[b]&&r[a+l]==r[b+l]; - } -  - voidDaint*r,int*sa,intNintm) + { -     inti,j,p,*x=wa,*y=wb,*T; +      for(i=0; i<m; i++) wws[i]=0; A      for(i=0; i<n; i++) wws[x[i]=r[i]]++; at      for(i=1; i<m; i++) wws[i]+=wws[i-1]; -      for(i=n-1; i>=0; i--) sa[--wws[x[i]]]=i; -      for(j=1, p=1; p<n; j*=2, m=p) -     { -  -          for(p=0, I=n-j; i<n; i++) y[p++]=i; in          for(i=0; i<n; i++)if(SA[I]&GT;=J) y[p++]=sa[i]-J; -          for(i=0; i<n; i++) wv[i]=X[y[i]]; to          for(i=0; i<m; i++) wws[i]=0; +          for(i=0; i<n; i++) wws[wv[i]]++; -          for(i=1; i<m; i++) wws[i]+=wws[i-1]; the          for(i=n-1; i>=0; i--) sa[--wws[wv[i]]]=Y[i]; *          for(t=x,x=y,y=t,p=1, x[sa[0]]=0, i=1; i<n; i++) $X[SA[I]]=CMP (y,sa[i-1],sa[i],j)? p1:p + +;Panax Notoginseng     } -     return; the } +  A voidCalheight (int*r,int*sa,intN) the { +     inti,j,k=0; -      for(i=1; i<=n; i++) rank[sa[i]]=i; $      for(i=0; i<n; height[rank[i++]]=k) $          for(k?k--:0, j=sa[rank[i]-1]; R[I+K]==R[J+K]; k++); -     return; - } the  - intMain ()Wuyi { theIos::sync_with_stdio (false); -Cin>>N; Wulen=0; -      for(intI=1; i<=n;i++) About     { $st[i]=Len; -Cin>>ts; -Tl=strlen (TS); -ln[i]=tl; A          for(intj=len;j<len+tl;j++) +         { the             Charch=ts[j-Len]; -             inttn=ch; $r[j]=tn; the         } thelen+=tl; ther[len]=1; thelen++; -     } inr[len]=0; the  theDa (r,sa,len+1, $); About calheight (R,sa,len); the  the     //for (int i=0;i<=len+1;i++) the     //cout< +     //cout<<endl; -      for(intI=1; i<=n;i++) the     {Bayi         inttmp=Rank[st[i]]; the         inttl=tmp,tr=tmp+1, tlen=Ln[i]; the          while((Height[tl]>=tlen) && (tl>=0)) tl--; -          while((Height[tr]>=tlen) && (Tr<=len)) tr++; -cout<<tr-tl<<Endl; the     } the  the     return 0; the}

BZOJ3172 suffix Array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.