题意:
长度为x的本质不同的串的出现次数
题解:
先处理出每一个节点所对应的子串出现的次数
然后取max就好了
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map> #define pi acos(-1.0)
#define eps 1e-9
#define fi first
#define se second
#define rtl rt<<1
#define rtr rt<<1|1
#define bug printf("******\n")
#define mem(a, b) memset(a,b,sizeof(a))
#define name2str(x) #x
#define fuck(x) cout<<#x" = "<<x<<endl
#define sfi(a) scanf("%d", &a)
#define sffi(a, b) scanf("%d %d", &a, &b)
#define sfffi(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define sffffi(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define sfL(a) scanf("%lld", &a)
#define sffL(a, b) scanf("%lld %lld", &a, &b)
#define sfffL(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define sffffL(a, b, c, d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d)
#define sfs(a) scanf("%s", a)
#define sffs(a, b) scanf("%s %s", a, b)
#define sfffs(a, b, c) scanf("%s %s %s", a, b, c)
#define sffffs(a, b, c, d) scanf("%s %s %s %s", a, b,c, d)
#define FIN freopen("../in.txt","r",stdin)
#define gcd(a, b) __gcd(a,b)
#define lowbit(x) x&-x
#define IO iOS::sync_with_stdio(false) using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const ULL seed = ;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int maxm = 8e6 + ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
const int maxn = ; struct Suffix_Automaton {
int last, tot, nxt[maxn << ][], fail[maxn << ];//last是未加入此字符前最长的前缀(整个串)所属的节点的编号
int len[maxn << ];// 最长子串的长度 (该节点子串数量 = len[x] - len[fa[x]])
int sa[maxn << ], c[maxn << ];
int sz[maxn << ];// 被后缀链接的个数,方便求节点字符串的个数
LL num[maxn << ];// 该状态子串的数量
LL maxx[maxn << ];// 长度为x的子串出现次数最多的子串的数目
LL sum[maxn << ];// 该节点后面所形成的自字符串的总数
LL subnum, sublen;// subnum表示不同字符串数目,sublen表示不同字符串总长度
int X[maxn << ], Y[maxn << ]; // Y表示排名为x的节点,X表示该长度前面还有多少个
void init() {
tot = last = ;
fail[] = len[] = ;
for (int i = ; i < ; i++) nxt[][i] = ;
} void extend(int c) {
int u = ++tot, v = last;
len[u] = len[v] + ;
num[u] = ;
for (; v && !nxt[v][c]; v = fail[v]) nxt[v][c] = u;
if (!v) fail[u] = , sz[]++;
else if (len[nxt[v][c]] == len[v] + ) fail[u] = nxt[v][c], sz[nxt[v][c]]++;
else {
int now = ++tot, cur = nxt[v][c];
len[now] = len[v] + ;
memcpy(nxt[now], nxt[cur], sizeof(nxt[cur]));
fail[now] = fail[cur];
fail[cur] = fail[u] = now;
for (; v && nxt[v][c] == cur; v = fail[v]) nxt[v][c] = now;
sz[now] += ;
}
last = u;
//return len[last] - len[fail[last]];//多添加一个子串所产生不同子串的个数
} void get_num() {// 每个节点子串出现的次数
for (int i = ; i <= tot; i++) X[len[i]]++;
for (int i = ; i <= tot; i++) X[i] += X[i - ];
for (int i = ; i <= tot; i++) Y[X[len[i]]--] = i;
for (int i = tot; i >= ; i--) num[fail[Y[i]]] += num[Y[i]];
} void get_maxx(int n) {// 长度为x的子串出现次数最多的子串的数目
get_num();
for (int i = ; i <= tot; i++) maxx[len[i]] = max(maxx[len[i]], num[i]);
} void get_sum() {// 该节点后面所形成的自字符串的总数
get_num();
for (int i = tot; i >= ; i--) {
sum[Y[i]] = ;
for (int j = ; j <= ; j++)
sum[Y[i]] += sum[nxt[Y[i]][j]];
}
} void get_subnum() {//本质不同的子串的个数
subnum = ;
for (int i = ; i <= tot; i++) subnum += len[i] - len[fail[i]];
} void get_sublen() {//本质不同的子串的总长度
sublen = ;
for (int i = ; i <= tot; i++) sublen += 1LL * (len[i] + len[fail[i]] + ) * (len[i] - len[fail[i]]) / ;
} void get_sa() { //获取sa数组
for (int i = ; i <= tot; i++) c[len[i]]++;
for (int i = ; i <= tot; i++) c[i] += c[i - ];
for (int i = tot; i >= ; i--) sa[c[len[i]]--] = i;
} int minn[maxn << ], mx[maxn << ];//多个串的最长公共子串
//minn[i]表示多个串在后缀自动机i节点最长公共子串,mx[i]表示单个串的最长公共子串 void match(char s[]) {
mem(mx, );
int n = strlen(s), p = , maxlen = ;
for (int i = ; i < n; i++) {
int c = s[i] - 'a';
if (nxt[p][c]) p = nxt[p][c], maxlen++;
else {
for (; p && !nxt[p][c]; p = fail[p]);
if (!p) p = , maxlen = ;
else maxlen = len[p] + , p = nxt[p][c];
}
mx[p] = max(mx[p], maxlen);
}
for (int i = tot; i; i--)
mx[fail[i]] = max(mx[fail[i]], min(len[fail[i]], mx[i]));
for (int i = tot; i; i--)
if (minn[i] == - || minn[i] > maxx[i]) minn[i] = mx[i];
} void get_kth(int k) {//求出字典序第K的子串
int pos = , cnt;
string s = "";
while (k) {
for (int i = ; i <= ; i++) {
if (nxt[pos][i] && k) {
cnt = nxt[pos][i];
if (sum[cnt] < k) k -= sum[cnt];
else {
k--;
pos = cnt;
s += (char) (i + 'a');
break;
}
}
}
}
cout << s << endl;
}
} sam; char s[maxn]; int main() {
#ifndef ONLINE_JUDGE
FIN;
#endif
sam.init();
sfs(s + );
int n = strlen(s + );
for (int i = ; i <= n; i++) sam.extend((s[i] - 'a'));
sam.get_maxx(n);
// fuck(n);
for (int i = ; i <= n; i++) printf("%d\n", sam.maxx[i]);
#ifndef ONLINE_JUDGE
cout << "Totle Time : " << (double) clock() / CLOCKS_PER_SEC << "s" << endl;
#endif
return ;
}