SUBST1 - New Distinct Substrings no tags  Given a string, we need to find the total number of its distinct substrings. Input T- number of test cases. T<=20; Each test case consists of one string, whose length is <= 50000 Output For each test case ou…
Given a string, we need to find the total number of its distinct substrings. Input T- number of test cases. T<=20; Each test case consists of one string, whose length is <= 50000 Output For each test case output one number saying the number of disti…
DISUBSTR - Distinct Substrings no tags  Given a string, we need to find the total number of its distinct substrings. Input T- number of test cases. T<=20; Each test case consists of one string, whose length is <= 1000 Output For each test case outpu…
694. Distinct Substrings Problem code: DISUBSTR   Given a string, we need to find the total number of its distinct substrings. Input T- number of test cases. T<=20;Each test case consists of one string, whose length is <= 1000 Output For each test c…
题意:求一个字符串的不相同的子串个数 n<=1000 思路:这是一道论文题 ..]of longint; n,i,m,ans,v,cas:longint; ch:ansistring; procedure swap(var x,y:longint); var t:longint; begin t:=x; x:=y; y:=t; end; function cmp(a,b,l:longint):boolean; begin exit((y[a]=y[b])and(y[a+l]=y[b+l]));…
[SPOJ]Distinct Substrings/New Distinct Substrings(后缀数组) 题面 Vjudge1 Vjudge2 题解 要求的是串的不同的子串个数 两道一模一样的题目 其实很容易: 总方案-不合法方案数 对于串进行后缀排序后 不合法方案数=相邻两个串的不合法方案数的和 也就是\(height\)的和 所以\[ans=\frac{n(n+1)}{2}-\sum_{i=1}^{len}height[i]\] #include<iostream> #include…
New Distinct Substrings(后缀数组) 给定一个字符串,求不相同的子串的个数.\(n<=50005\). 显然,任何一个子串一定是后缀上的前缀.先(按套路)把后缀排好序,对于当前的后缀\(S_i\),显然他有\(n-sa[i]\)个前缀.其中,有\(height[i]\)个前缀字符串在编号比它小的后缀中出现过,因此它对答案的贡献是\(n-sa[i]-height[i]\). #include <cstdio> #include <cstring> usin…
705. New Distinct Substrings Problem code: SUBST1 Given a string, we need to find the total number of its distinct substrings. Input T- number of test cases. T<=20; Each test case consists of one string, whose length is <= 50000 Output For each test…
[题目链接] http://www.spoj.com/problems/SUBST1/ [题目大意] 给出一个串,求出不相同的子串的个数. [题解] 对原串做一遍后缀数组,按照后缀的名次进行遍历, 每个后缀对答案的贡献为n-sa[i]+1-h[i], 因为排名相邻的后缀一定是公共前缀最长的, 那么就可以有效地通过LCP去除重复计算的子串. [代码] #include <cstdio> #include <cstring> #include <algorithm> usi…
Distinct Substrings 题意 求一个字符串有多少个不同的子串. 分析 又一次体现了后缀数组的强大. 因为对于任意子串,一定是这个字符串的某个后缀的前缀. 我们直接去遍历排好序后的后缀字符串(也就是 \(sa\) 数组),每遍历到一个后缀字符串,会新添数量为这个后缀字符串的长度的前缀,但是要减去 \(height[i]\),即公共前缀的长度,因为前面已经添加过了这个数量的前缀串. code #include<bits/stdc++.h> using namespace std;…