给一个长度不超过90000的串S,每次询问它的所有不同子串中,字典序第K小的,询问不超过500个。
很经典的题目了,简单的来说就是1,建SAM,2,dfs求每个串包含了多少串,3,从SAM的头往后面找,每次从’a’找到’z’,一但找到哪个包含的串数比k多,那么就判定当前找的字母属于我们找的子串。(因为是从a开始的)。否则,k比一个串所包含的串总数还大,就减去这个字母代表的串数。
//
// Created by acer on 2021/2/16.
//
//判断子串,不同子串个数,所有子串字典序第i大,最长公共子串
#include <cstring>
#include <iostream>
#include "string"
#define mem(x, i) memset(x,i,sizeof(x))
using namespace std;
const int MAXN = 3e5 + 10;
int len[MAXN << 1];
int ch[MAXN << 1][27];
int fa[MAXN << 1];
int last = 1;
int tot = 1;
int p;
void add(int c) {
p = last;
last = ++tot;
int np = last;
len[np] = len[p] + 1;
for (; p && !(ch[p][c]); p = fa[p]) ch[p][c] = np;