题目链接:hdu_5769_Substring

题意:

给你一个字符a和一个串b,问你有多少个包括a的字串

题解:

 #include<bits/stdc++.h>
#define F(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
typedef long long ll;
namespace suffixarray{
#define FN(n) for(int i=0;i<n;i++)
const int N =1E5+;//字符串长度
int rnk[N],sa[N],height[N],c[N];char s[N];
void getsa(int n,int m,int *x=rnk,int *y=height){
FN(m)c[i]=;FN(n)c[x[i]=s[i]]++;FN(m)c[i+]+=c[i];
for(int i=n-;i>=;i--)sa[--c[x[i]]]=i;
for(int k=,p;p=,k<=n;k=p>=n?N:k<<,m=p){
for(int i=n-k;i<n;i++)y[p++]=i;
FN(n)if(sa[i]>=k)y[p++]=sa[i]-k;
FN(m)c[i]=;FN(n)c[x[y[i]]]++;FN(m)c[i+]+=c[i];
for(int i=n-;i>=;i--)sa[--c[x[y[i]]]]=y[i];
swap(x,y),p=,x[sa[]]=;
for(int i=;i<n;i++)
x[sa[i]]=y[sa[i-]]==y[sa[i]]&&y[sa[i-]+k]==y[sa[i]+k]?p-:p++;
}
FN(n)rnk[sa[i]]=i;
for(int i=,j,k=;i<n-;height[rnk[i++]]=k)
for(k=k?k-:k,j=sa[rnk[i]-];s[i+k]==s[j+k];k++);
}
}
using namespace suffixarray;
int t,ic=,nxt[N];char aim[];
int main(){
scanf("%d",&t);
while(t--)
{
scanf("%s%s",aim,s),aim[]-='a'-;
int len=strlen(s);
F(i,,len-)s[i]=s[i]-'a'+;
getsa(len+,);
for(int i=len-,x=len;i>=;i--)
{
if(s[i]==aim[])x=i;
nxt[i]=x;
}
ll ans=;
F(i,,len)ans+=len-max(nxt[sa[i]],sa[i]+height[i]);
printf("Case #%d: %lld\n",ic++,ans);
}
return ;
}

hdu_5769_Substring(后缀数组)的更多相关文章

  1. 后缀数组的倍增算法(Prefix Doubling)

    后缀数组的倍增算法(Prefix Doubling) 文本内容除特殊注明外,均在知识共享署名-非商业性使用-相同方式共享 3.0协议下提供,附加条款亦可能应用. 最近在自学习BWT算法(Burrows ...

  2. BZOJ 4199: [Noi2015]品酒大会 [后缀数组 带权并查集]

    4199: [Noi2015]品酒大会 UOJ:http://uoj.ac/problem/131 一年一度的“幻影阁夏日品酒大会”隆重开幕了.大会包含品尝和趣味挑战两个环节,分别向优胜者颁发“首席品 ...

  3. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  4. POJ3693 Maximum repetition substring [后缀数组 ST表]

    Maximum repetition substring Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9458   Acc ...

  5. POJ1743 Musical Theme [后缀数组]

    Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 27539   Accepted: 9290 De ...

  6. 后缀数组(suffix array)详解

    写在前面 在字符串处理当中,后缀树和后缀数组都是非常有力的工具. 其中后缀树大家了解得比较多,关于后缀数组则很少见于国内的资料. 其实后缀数组是后缀树的一个非常精巧的替代品,它比后缀树容易编程实现, ...

  7. 【UOJ #35】后缀排序 后缀数组模板

    http://uoj.ac/problem/35 以前做后缀数组的题直接粘模板...现在重新写一下模板 注意用来基数排序的数组一定要开到N. #include<cstdio> #inclu ...

  8. 【BZOJ-2119】股市的预测 后缀数组

    2119: 股市的预测 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 334  Solved: 154[Submit][Status][Discuss ...

  9. 【BZOJ-4698】Sandy的卡片 后缀数组

    4698: Sdoi2008 Sandy的卡片 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 140  Solved: 55[Submit][Stat ...

随机推荐

  1. 12c windows auto installl

    --config for oralce_envset ORACLE_HOME=c:\app\oracle\product\12.1.0\dbhome_1set ORACLE_SID=testuatse ...

  2. hibernate主键generator属性介绍

    increment(递增) 用于为long, short或者int类型生成唯一标识.只有在没有其他进程往同一张表中插入数据时才能使用. 在集群下不要使用. identity (标识)对DB2,MySQ ...

  3. php 微信 统一下单 接口实例

    <?phpclass wechatAppPay { //接口API URL前缀 const API_URL_PREFIX = 'https://api.mch.weixin.qq.com'; / ...

  4. delphi 关键字

    下面的关键字不能被重新定义或用作标志符:and array as asm begin case class const constructor destructor dispinterface div ...

  5. JavaBean 反射机制实现自动配置数据

    声明:该版本是没完成的.该博文只做记录代码用 String memberType(String name) throws Exception { return getType(getClass().g ...

  6. cocoaPods使用

    1更新版本:pod repo update 有时太老的gem版本,搜索不到最新SDK库 特殊情况下,由于网络或者别的原因,通过 CocoaPods 下载的文件可能会有问题. 这时候您可以删除 Coco ...

  7. Generating Faces with Deconvolution Networks

    用深度学习做人脸合成,website:https://zo7.github.io/blog/2016/09/25/generating-faces.html 受启发于 Learning to Gene ...

  8. [JS高程]引用类型(Object、Array)

    引用类型:Object.Array Object: person.name   =>推荐,除非必须使用变量([])来表示 person["name"] 区别:[]可以通过变量 ...

  9. hancher57公众号突破3000人

  10. HDU 1241Oil Deposits (DFS)

    Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground ...