SP8093 JZPGYZ - Sevenk Love Oimaster

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SP8093 JZPGYZ - Sevenk Love Oimaster相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/putc' title='putc'>putc   cond   utc   get   seve   ++   match   class   浣嶇疆   

浼犻€侀棬

骞夸箟鍚庣紑鑷姩鏈衡€︹€?/p>

鍏跺疄涔熶笉鏄緢闅剧悊瑙o紝灏辨槸姣忔SAM鎻掑叆涓€涓覆涔嬪悗锛屾彃鍏ユ柊鐨勪覆鐨勬椂鍊欙紝瑕佹妸last閲嶆柊璋冨埌1鐨勪綅缃紝鍏辩敤涓€浜涜妭鐐广€?/p>

杩欎釜棰樻垜浠鍏堣棰勫鐞嗗嚭鏉ユ瘡涓姸鎬佽澶氬皯涓覆鍏辩敤銆?del>鎸烘毚鍔涚殑灏辨槸姣忔鎶婅妭鐐规煋鑹诧紝濡傛灉鑺傜偣娌¤鏌撹壊灏辩粰浠栨煋涓€涓嬶紝鐒跺悗璁板綍褰撳墠鑺傜偣鍙堣鍏辩敤浜嗕竴娆°€?/p>

鏈€鍚庤窇鐨勬椂鍊欏拰鍖归厤鏄竴鏍风殑锛屾瘡娆¤緭鍑烘湯灏捐妭鐐瑰叡鐢ㄦ鏁板嵆鍙€?/p>

#include<bits/stdc++.h>
#define rep(i,a,n) for(register int i = a;i <= n;i++)
#define per(i,n,a) for(register int i = n;i >= a;i--)
#define enter putchar(鈥榎n鈥?
#define pr pair<int,int>
#define mp make_pair
#define fi first
#define sc second
using namespace std;
typedef long long ll;
const int M = 100005;
const int N = 10000005;
const int INF = 2147483647;

int read()
{
   int ans = 0,op = 1;
   char ch = getchar();
   while(ch < 鈥?鈥?|| ch > 鈥?鈥? {if(ch == 鈥?鈥? op = -1;ch = getchar();}
   while(ch >=鈥?鈥?&& ch <= 鈥?鈥? ans = ans * 10 + ch - 鈥?鈥?ch = getchar();
   return ans * op;
}

string s[M],t;
int n,m,k,times[M<<1],col[M<<1];

struct Suffix
{
   int last,cnt,ch[M<<1][26],fa[M<<1],l[M<<1];
   void extend(int c)
   {
      int p = last,np = ++cnt;
      last = cnt,l[np] = l[p] + 1;
      while(p && !ch[p][c]) ch[p][c] = np,p = fa[p];
      if(!p) {fa[np] = 1;return;}
      int q = ch[p][c];
      if(l[q] == l[p] + 1) fa[np] = q;
      else
      {
     int nq = ++cnt;
     l[nq] = l[p] + 1,memcpy(ch[nq],ch[q],sizeof(ch[q]));
     fa[nq] = fa[q],fa[q] = fa[np] = nq;
     while(ch[p][c] == q) ch[p][c] = nq,p = fa[p];
      }
   }
   void cal(string b,int q)
   {
      int cur = 1,h = b.length();
      rep(j,0,h-1)
      {
     cur = ch[cur][b[j] - 鈥榓鈥榏;
     int t = cur;
     while(t && col[t] != q) times[t]++,col[t] = q,t = fa[t];
      }
   }
   void match(string b)
   {
      int cur = 1;
      rep(i,0,k-1) cur = ch[cur][b[i]-鈥榓鈥榏;
      printf("%d
",times[cur]);
   }
}SAM;

int main()
{
   n = read(),m = read();
   SAM.cnt = 1;
   rep(i,1,n)
   {
      cin >> s[i],k = s[i].length();
      SAM.last = 1;
      rep(j,0,k-1) SAM.extend(s[i][j] - 鈥榓鈥?;
   }
   rep(i,1,n) SAM.cal(s[i],i);
   while(m--) cin >> t,k = t.length(),SAM.match(t);
   return 0;
}

以上是关于SP8093 JZPGYZ - Sevenk Love Oimaster的主要内容,如果未能解决你的问题,请参考以下文章

BZOJ2780[Spoj]8093 Sevenk Love Oimaster 广义后缀自动机

Spoj8093 Sevenk Love Oimaster

bzoj2780[Spoj]8093 Sevenk Love Oimaster 广义后缀自动机

[BZOJ2780][SPOJ8093]Sevenk Love Oimaster

BZOJ 2780: [Spoj]8093 Sevenk Love Oimaster( 后缀数组 + 二分 + RMQ + 树状数组 )

luogu SP8093 后缀自动机+树状数组+dfs序