题目要求AB串相同子串的对数
我们可以知道对于长度为K的相同子串可以分为两个部分
- 第k+1个字符不相同的部分,我们可以用带权并查集合并实现统计。
- 第k+1个字符相同的部分,直接由k+1长度的结果合并过来。就是在一操作后实现一个后缀和。
#include<algorithm>
#include<vector>
#include<iostream>
#include<math.h>
#include<cstring>
#include<string>
#include<stack>
#define qcin; ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pll;
const int maxn = 400100;
typedef int arr[maxn];
void file(int x){if(x&&fopen("in.txt","r")){freopen("in.txt","r",stdin);}}
struct ST{
int mm[maxn],dp[maxn][22],k,sz;
//const int&(*fun[2])(const int&,const int&)={max,min};
void init(int n,int b[],int fl){
mm[0]=-1;