思路

$SAM$练手题，将原串重复一遍插入到$SAM$中，然后贪心走长度为n的一个路径即可。

代码

/*
* @Author: wxyww
* @Date:   2019-07-11 11:09:25
*/
#include<cstdio>
#include<map>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<ctime>
using namespace std;
typedef long long ll;
const int N = 600000 + 100;
ll x=0,f=1;char c=getchar();
while(c<'0'||c>'9') {
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9') {
x=x*10+c-'0';
c=getchar();
}
return x*f;
}
struct node {
int len,fa;
map<int,int>ch;
}SAM[N << 1];
int lst = 1,tot = 1;
int cur = ++tot,p = lst;
SAM[cur].len = SAM[p].len + 1;
while(p && !SAM[p].ch[c]) {
SAM[p].ch[c] = cur;
p = SAM[p].fa;
}
if(!p) SAM[cur].fa = 1;
else {
int q = SAM[p].ch[c];
if(SAM[q].len == SAM[p].len + 1) SAM[cur].fa = q;
else {
int clone = ++tot;
SAM[clone] = SAM[q];
SAM[clone].len = SAM[p].len + 1;
while(p && SAM[p].ch[c] == q) {
SAM[p].ch[c] = clone;
p = SAM[p].fa;
}
SAM[q].fa = SAM[cur].fa = clone;
}
}
lst = cur;
}
int a[N];
int main() {
}