求不重复的子串个数

用所有的减去height就好了 推出来的。。。

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff; char a[maxn];
int s[maxn];
int sa[maxn], t[maxn], t2[maxn], c[maxn], n;
int ran[maxn], height[maxn]; void get_sa(int m)
{
int i, *x = t, *y = t2;
for(i = ; i < m; i++) c[i] = ;
for(i = ; i < n; i++) c[x[i] = s[i]]++;
for(i = ; i < m; i++) c[i] += c[i-];
for(i = n-; i >= ; i--) sa[--c[x[i]]] = i;
for(int k = ; k <= n; k <<= )
{
int p = ;
for(i = n-k; i < n; i++) y[p++] = i;
for(i = ; i < n; i++) if(sa[i] >= k) y[p++] = sa[i] - k;
for(i = ; i < m; i++) c[i] = ;
for(i = ; i < n; i++) c[x[y[i]]]++;
for(i = ; i< m; i++) c[i] += c[i-];
for(i = n-; i >= ; i--) sa[--c[x[y[i]]]] = y[i];
swap(x, y);
p = ; x[sa[]] = ;
for(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;
}
int k = ;
for(i = ; i < n; i++) ran[sa[i]] = i;
for(i = ; i < n; i++)
{
if(k) k--;
int j = sa[ran[i]-];
while(s[i+k] == s[j+k]) k++;
height[ran[i]] = k;
}
} int main()
{
int T;
rd(T);
while(T--)
{
rs(a);
n = strlen(a);
rep(i, , n)
s[i] = a[i];
int sum = n*(n+)/;
s[n++] = ;
get_sa();
rep(i, , n)
sum -= height[i];
cout<< sum <<endl; } return ;
}

Distinct Substrings SPOJ - DISUBSTR(后缀数组水题)的更多相关文章

  1. Distinct Substrings SPOJ - DISUBSTR 后缀数组

    Given a string, we need to find the total number of its distinct substrings. Input T- number of test ...

  2. Spoj-DISUBSTR - Distinct Substrings~New Distinct Substrings SPOJ - SUBST1~(后缀数组求解子串个数)

    Spoj-DISUBSTR - Distinct Substrings New Distinct Substrings SPOJ - SUBST1 我是根据kuangbin的后缀数组专题来的 这两题题 ...

  3. 705. New Distinct Substrings spoj(后缀数组求所有不同子串)

    705. New Distinct Substrings Problem code: SUBST1 Given a string, we need to find the total number o ...

  4. SPOJ DISUBSTR ——后缀数组

    [题目分析] 后缀数组模板题. 由于height数组存在RMQ的性质. 那么对于一个后缀,与前面相同的串总共有h[i]+sa[i]个.然后求和即可. [代码](模板来自Claris,这个板子太漂亮了) ...

  5. SPOJ DISUBSTR 后缀数组

    题目链接:http://www.spoj.com/problems/DISUBSTR/en/ 题意:给定一个字符串,求不相同的子串个数. 思路:直接根据09年oi论文<<后缀数组——出来字 ...

  6. [spoj DISUBSTR]后缀数组统计不同子串个数

    题目链接:https://vjudge.net/contest/70655#problem/C 后缀数组的又一神奇应用.不同子串的个数,实际上就是所有后缀的不同前缀的个数. 考虑所有的后缀按照rank ...

  7. poj2774(后缀数组水题)

    http://poj.org/problem?id=2774 题意:给你两串字符,要你找出在这两串字符中都出现过的最长子串......... 思路:先用个分隔符将两个字符串连接起来,再用后缀数组求出h ...

  8. BZOJ 1031 [JSOI2007]字符加密Cipher | 后缀数组模板题

    BZOJ 1031 [JSOI2007]字符加密Cipher | 后缀数组模板题 将字符串复制一遍接在原串后面,然后后缀排序即可. #include <cmath> #include &l ...

  9. POJ 2774 Long Long Message 后缀数组模板题

    题意 给定字符串A.B,求其最长公共子串 后缀数组模板题,求出height数组,判断sa[i]与sa[i-1]是否分属字符串A.B,统计答案即可. #include <cstdio> #i ...

随机推荐

  1. cpp-variable-lifetime

    #include <cstdio> #include <iostream> using namespace std; class TmpClass; void FuncScop ...

  2. Laya中的Image、Texture、WebGLImage

    Image Image是Laya的一个UI组件,继承自Component. Image.bitmap属性,是AutoBitmap类型:AutoBitmap继承自Graphics,负责处理图片九宫格逻辑 ...

  3. 电梯调度 结对项目开发(郭林林&胡潇丹)

    (一)需求分析: 上升,下降,开门,关门: 超过负载以后发出警报,下去乘客: 电梯出现故障后,电梯停止: 电梯楼层的输入框可以同时指定所要到的楼层,也是楼层的显示框: 电梯同时记录多个状态,即为到达多 ...

  4. linux的date命令使用指定时间的加减方法与异常

    在一般网页里,date命令减时间方法为: date -d '-100 days' 我的需求是,在指定时间上减8小时.按一般理解来看,命令写成如下样子(有异常错误的写法): date -d " ...

  5. umask命令详解

    基础命令学习目录首页 原文链接:https://blog.csdn.net/stpeace/article/details/45509425        umask命令用得相对不多, 而umask函 ...

  6. 【转】Java生成plist下载ipa文件

    我们在上传ipa想要安装的时候必须要通过plist文件去下载,并且还要遵循 itms-services协议. 意思就是,第一步我们要生成一个plist文件, 第二步生成一个html文件,用来指向pli ...

  7. hadoop在章鱼大数据平台下的安装与配置

    本次所用的软件版本: ubuntu :14.04 Hadoop:hadoop-2.6.0-cdh5.4.5 jdk:jdk-7u75-linux-x64 Hive: Hbase: 一.配置基本环境 1 ...

  8. 《Spring1之 第一次站立会议(重发)》

    < 第一次站立会议(重发)> 昨天,我对我们团队要做的项目进行了相关资料的查找,我找到了服务器和客户端的相关代码以及找到了把它们通信所使用TCP/IP等协议: 今天,我把找到的代码和协议资 ...

  9. 【搜索】POJ-3187 枚举全排列

    一.题目 Description FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to ...

  10. 学习总结:jQuery插件开发模式和结构

    学习博客链接: ①https://www.cnblogs.com/cyStyle/ ② https://www.cnblogs.com/chengyunshen/p/7277305.html ③ ht ...