Bzoj 4566 Jzyzoj 1547 [haoi2016t5] Find the same substring suffix array

Source: Internet
Author: User

http://172.20.6.3/Problem_Show.asp?id=1547

http://www.lydsy.com/JudgeOnline/problem.php?id=4566

It seems that the suffix is a positive solution, but the suffix array + and check set can also mess with a off, define the string size of integer variables when char siz cause re or something; I'm probably a zz.

By the way, save a board, copy Purple Xuan learn elder sister's board.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <cmath>6 using namespacestd;7 Const intmaxn=200010;8 Const intPl= -;9 intsa[maxn*2+pl]={};//Number I is an array starting from sa[i]Ten intrk[maxn*2+pl]={};//Ranking of I One intheight[maxn*2+pl]={};//The longest same prefix length in rank i-1 as the rank no. i A inttemp[maxn*2+pl]={};//Temporary rankings - intcnt[maxn*2+pl]={};//the number of prefixes (prefixes and) of the Type I (dictionary order) prefix - intp[maxn*2+pl]={};//temporary storage of the last SA, processing the suffix length of different cases.  the Charch[maxn*2+pl]={},ch1[maxn]={},ch2[maxn]={}; - intSiz1,siz2,siz; - intfa[maxn*2+pl]={},a[maxn*2+pl]={},lef[maxn*2+pl]={},rig[maxn*2+pl]={}; -InlineBOOLEquintXintYintL) {returnrk[x]==rk[y]&&rk[x+l]==rk[y+l];} + voidSA () { -      for(intI=1; i<=siz;i++) rk[i]=ch[i],sa[i]=i; +      for(inti,sig=255, l=0, pos=0;p Os<siz;sig=pos) {//L starting from 0 is pretreatment Apos=0; at          for(i=siz-l+1; i<=siz;i++) p[++pos]=i; -          for(i=1; i<=siz;i++)if(sa[i]>l) p[++pos]=sa[i]-l; -          for(i=0; i<=sig;i++) cnt[i]=0; -          for(i=1; i<=siz;i++) cnt[rk[p[i]]]++; -          for(i=1; i<=sig;i++) cnt[i]+=cnt[i-1]; -          for(i=siz;i>0; i--) {sa[cnt[rk[p[i]]]]=p[i];cnt[rk[p[i]]]--;} inpos=0; -          for(i=1; i<=siz;i++){ to             if(Equ (sa[i],sa[i-1],l)) temp[sa[i]]=Pos; +             Elsetemp[sa[i]]=++Pos; -} for(i=1; i<=siz;i++) rk[i]=Temp[i]; the         if(l==0) l=1; *         Elsel<<=1; $     }Panax Notoginseng      for(intI=1, k=0; i<=siz;i++){ -         /*for each suffix of a position, the suffix of the next position can match the shortest length the must be greater than or equal to the length at which the position can be matched-1, obviously. So it's an O (n) algorithm. +         */ A         if(rk[i]==1) {k=0;Continue;} the         if(k>0) k--; +         intj=sa[rk[i]-1]; -          while(Ch[i+k]==ch[j+k]) k++; $height[rk[i]]=K; $     } - } - BOOLMCMP (intXintY) {returnHeight[x]>height[y];} the intGETFA (intx) { -     if(X!=fa[x]) fa[x]=GETFA (fa[x]);Wuyi     returnFa[x]; the } - intMain () { Wu     //freopen ("a.in", "R", stdin); -scanf"%s", &ch1); siz1=strlen (CH1); Aboutscanf"%s", &AMP;CH2); siz2=strlen (CH2); $ch[siz1+1]='Z'+1; siz=siz1+siz2+1; -      for(intI=0; i<siz1;i++) ch[i+1]=Ch1[i]; -      for(intI=0; i<siz2;i++) ch[siz1+2+i]=Ch2[i]; - SA (); A      for(intI=1; i<=siz;i++){ +a[i]=fa[i]=i; theLef[i]= (sa[i]<=siz1); -rig[i]=1^Lef[i]; $}sort (A +1, A +1+siz,mcmp); the     Long Longans=0; the     intx, y; the      for(intI=1; i<=siz;i++){ the         if(a[i]==1)Continue; -X=GETFA (A[i]); Y=GETFA (a[i]-1); inans+= (Long Long) height[a[i]]* (Long Long) (lef[x]*rig[y]+rig[x]*lef[y]); thelef[x]+=lef[y];rig[x]+=rig[y];fa[y]=x; the}printf ("%lld\n", ans); About     return 0; the}
View Code

Bzoj 4566 Jzyzoj 1547 [haoi2016t5] Find the same substring 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.