hdu3518 Boring Counting[后缀排序]
裸的统计不同的重复出现子串(不重叠)种数的题。
多次使用后缀排序要注意小细节。y数组在重复使用时一定要清空,看那个line25 +k就明白了 ,cnt也要清空,为什么就不说了
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T>inline char MAX(T&A,T B){return A<B?(A=B,):;}
template<typename T>inline char MIN(T&A,T B){return A>B?(A=B,):;}
const int N=+;
char s[N];
int n,m;
ll ans; int sa[N],rk[N],x[N],y[N],cnt[N],h[N],p;
inline void build(){
memset(cnt,,sizeof cnt);memset(y,,sizeof y);//
for(register int i=;i<=n;++i)++cnt[x[i]=s[i]];
for(register int i=;i<=m;++i)cnt[i]+=cnt[i-];
for(register int i=n;i;--i)sa[cnt[x[i]]--]=i;
for(register int k=;k<n;k<<=,p=){
for(register int i=n-k+;i<=n;++i)y[++p]=i;
for(register int i=;i<=n;++i)if(sa[i]>k)y[++p]=sa[i]-k;
for(register int i=;i<=m;++i)cnt[i]=;
for(register int i=;i<=n;++i)++cnt[x[y[i]]];
for(register int i=;i<=m;++i)cnt[i]+=cnt[i-];
for(register int i=n;i;--i)sa[cnt[x[y[i]]]--]=y[i];
swap(x,y);x[sa[]]=p=;
for(register int i=;i<=n;++i)x[sa[i]]=y[sa[i-]]==y[sa[i]]&&y[sa[i-]+k]==y[sa[i]+k]?p:++p;
if(p==n)break; m=p;
}p=;
// for(register int i=1;i<=n;++i)printf("%d %d\n",i,x[i]);
for(register int i=;i<=n;h[x[i]]=p,p?--p:,++i)while(s[i+p]==s[sa[x[i]-]+p]&&++p);
} inline void search(int k){
int l=sa[],r=sa[];
for(register int i=;i<=n;++i){
if(h[i]<k){r-l>=k?++ans:;l=r=sa[i];}
MIN(l,sa[i]),MAX(r,sa[i]);
}
r-l>=k?++ans:;
} int main(){
while(~scanf("%s",s+)){
if(s[]=='#')break;
n=strlen(s+),m=,ans=,p=,build();
for(register int i=;i<=n/;++i)search(i);
printf("%lld\n",ans);
}
return ;
}
hdu3518 Boring Counting[后缀排序]的更多相关文章
- hdu3518 Boring counting(后缀数组)
Boring counting 题目传送门 解题思路 后缀数组.枚举每种长度,对于每个字符串,记录其最大起始位置和最小起始位置,比较是否重合. 代码如下 #include <bits/stdc+ ...
- hdu3518 Boring counting
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=3518 题目: Boring counting Time Limit: 2000/1000 MS ...
- [HDU3518]Boring counting(后缀数组)
传送门 求出现超过1次的不重叠子串的个数 根据论文中的方法. 枚举子串的长度 k. 用 k 给 height 数组分组,每一组求解,看看当前组的位置最靠后的后缀和位置最靠前的后缀所差个数是否大于长度, ...
- hdu 3518 Boring counting 后缀数组LCP
题目链接 题意:给定长度为n(n <= 1000)的只含小写字母的字符串,问字符串子串不重叠出现最少两次的不同子串个数; input: aaaa ababcabb aaaaaa # output ...
- hdu 3518 Boring counting 后缀数组基础题
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- hdu 3518 Boring counting 后缀数组
题目链接 根据height数组的性质分组计算. #include <iostream> #include <vector> #include <cstdio> #i ...
- hdu 3518 Boring counting 后缀数组 height分组
题目链接 题意 对于给定的字符串,求有多少个 不重叠的子串 出现次数 \(\geq 2\). 思路 枚举子串长度 \(len\),以此作为分界值来对 \(height\) 值进行划分. 显然,对于每一 ...
- 后缀数组 --- HDU 3518 Boring counting
Boring counting Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=3518 Mean: 给你一个字符串,求:至少出 ...
- Boring counting HDU - 3518 (后缀数组)
Boring counting \[ Time Limit: 1000 ms \quad Memory Limit: 32768 kB \] 题意 给出一个字符串,求出其中出现两次及以上的子串个数,要 ...
随机推荐
- python windows package/module 安装
方法一: cmd中运行pip install xx 注意:1.pip添加至环境变量 2.系统自带这些安装模块 运行pip freeze > requirements.txt 可以在require ...
- ssh port forwarding
SSH端口转发,总是忘记,今天记录下.端口转发有两种,一个是local一个是remote(可能还有一种dynamic,还没有研究) 贴个链接 https://www.ssh.com/ssh/tunne ...
- mongodb的IO测试工具 mongoperf
之前没发现mongoperf这个工具,测试IO的状态用的是iostat来进行观察. mongoperf < myjsonconfigfile echo "{nThreads:2,fi ...
- js 检测客户端网速
<!doctype html> <html> <head> <meta http-equiv=Content-Type content="text/ ...
- python读写数据篇
一.读写数据1.读数据 #使用open打开文件后一定要记得调用文件对象的close()方法.比如可以用try/finally语句来确保最后能关闭文件.file_object = open('thefi ...
- http协议详解-经典篇
本文转载至 http://www.cnblogs.com/flychen/archive/2012/11/28/2792206.html ————————————————————————————— ...
- 安装anaconda及pytorch
安装anaconda,下载64位版本安装https://www.anaconda.com/download/ 官网比较慢,可到清华开源镜像站上下载 环境变量: D:\Anaconda3;D:\A ...
- 五个知识体系之-SQL学习-第二天
创建数据:INSERT INTO userinfo(userid,username,job,level1,companyage) VALUES ('001','xl001','test','P1',' ...
- 【BZOJ4241】历史研究 分块
[BZOJ4241]历史研究 Description IOI国历史研究的第一人——JOI教授,最近获得了一份被认为是古代IOI国的住民写下的日记.JOI教授为了通过这份日记来研究古代IOI国的生活,开 ...
- live555二次开发经验总结:RTSPClient客户端与RTSPServer服务器
live555介绍 安防领域的流媒体开发者估计没有谁不知道live555的,可能并不是因为其架构有多牛,代码有多好看,而是因为这玩意存在的年限实在是太长了,从changelog来看,live555从2 ...