"Bzoj" "3473" string

Source: Internet
Author: User

Suffix array

Orz ZYF God will not do ah, first pit ... sigh

1 //Bzoj 34732#include <vector>3#include <cstdio>4#include <cstring>5#include <cstdlib>6#include <iostream>7#include <algorithm>8 #defineRep (i,n) for (int i=0;i<n;++i)9 #defineF (i,j,n) for (int i=j;i<=n;++i)Ten #defineD (i,j,n) for (int i=j;i>=n;--i) One #definePB Push_back A using namespacestd; -typedefLong LongLL; -InlineintGetint () { the     intR=1, v=0;CharCh=GetChar (); -      for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') r=-1; -      for(; isdigit (ch); Ch=getchar ()) v=v*Ten+ch-'0'; -     returnr*v; + } - Const intn=1e5+Ten, inf=~0u>>2; + /*******************template********************/ A intSa[n],rank[n],height[n],belong[n],ans[n]; at intWa[n],wb[n],c[n],n,q,a[n]; - BOOLcmpint*r,intAintBintl) { -     returnR[A]==R[B] && r[a+l]==r[b+l]; - } - voidDA (int*s,int*sa,intNintm) { -     inti,j,p,*x=wa,*y=WB; inRep (i,m) c[i]=0; -Rep (I,n) c[x[i]=s[i]]++; toF (I,1, M-1) c[i]+=c[i-1]; +D (i,n-1,0) sa[--c[x[i]]]=i; -      for(j=1, p=0;p <n;j<<=1, m=p) { the          for(p=0, i=n-j;i<n;i++) y[p++]=i; *Rep (I,n)if(SA[I]&GT;=J) y[p++]=sa[i]-J; $ Panax NotoginsengRep (i,m) c[i]=0; -Rep (I,n) c[x[y[i]]]++; theF (I,1, M-1) c[i]+=c[i-1]; +D (i,n-1,0) sa[--c[x[y[i]]]]=Y[i]; ASwap (x, y); p=1; x[sa[0]]=0; theF (I,1, N-1) x[sa[i]]=cmp (y,sa[i-1],SA[I],J)? P1: p++; +     } - } $ voidCalheight (int*s,int*sa,intN) { $     intk=0; -F (I,1, N) rank[sa[i]]=i; - Rep (i,n) { the         if(k) k--; -         intj=sa[rank[i]-1];Wuyi          while(S[i+k]==s[j+k]) k++; theheight[rank[i]]=K; -     } Wu } - CharS[n]; About intMain () { $ #ifndef Online_judge -Freopen ("3473.in","R", stdin); -Freopen ("3473.out","W", stdout); - #endif AN=getint (); Q=getint ()-1; +     intL=0; theF (I,1, N) { -scanf"%s", s+l); $L=strlen (s); thes[l++]='a'-5; the     } theRep (i,l) a[i]=s[i]-'a'+Ten; thel--; -DA (a,sa,l+1, A); in calheight (a,sa,l); the ST (); the     inttmp=1; About Rep (i,l) { the         if(s[i]<Ten) {tmp++;Continue;} thebelong[rank[i]]=tmp; the     } +     intt=1, k=0; -F (I,1Lif(Belong[i]) { the         if(!cnt[belong[i]]) k++;Bayicnt[belong[i]]++; the         if(k<=q) { the              for(; K (cnt[belong[t]]==1) >=q; k-= (cnt[belong[t]]==1),--cnt[belong[t++]]); -rec[i]=T; -         } the     } theF (I,1, N) { theLL ans=0;intk=0; the F (J, -     return 0; the}
View Code 3473: String time limit:20 Sec Memory limit:256 MB
submit:121 solved:53
[Submit] [Status] [Discuss] Descriptiongiven n strings, ask how many substrings (not including empty strings) of each string are substrings of at least k strings in all n strings? InputThe first line is two integers n,K. next n rows are a string per line. Outputa row of n integers, and the first integer represents the answer to the I-string. Sample Input3 1
Abc
A
Ab
Sample Output6 1 3HINT



For 100% of data, 1<=n,k<=10^5, the total length of all strings is not more than 10^5, and the string contains only lowercase letters.

Source

Adera 1 cup winter camp simulation game

[Submit] [Status] [Discuss]

"Bzoj" "3473" string

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.