题意:定义一个串合法,在n个串中出现次数在li到ri中.问s的所有本质的子串有是多少合法的

题解:把所有串用分隔符分开建sam,记录一个该节点对应每个串的出现次数,topo排序后,当该节点s出现次数不为0,而且其他串出现次数满足条件,那么该节点对应的所有子串都满足条件(因为后缀相同,在同一个串中出现次数肯定相同),那么把该节点对应子串个数加到答案中即可

//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
//#define ls l,m,rt<<1
//#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;} using namespace std; const ull ba=233;
const db eps=1e-7;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=600000+10,maxn=100000+10,inf=0x3f3f3f3f; int n,L[20],R[20];
struct SAM{
int last,cnt;
int ch[N<<1][27],fa[N<<1],l[N<<1],sz[N<<1][15];
int a[N<<1],c[N<<1];
void ins(int c,int op){
int p=last,np=++cnt;last=np;l[np]=l[p]+1;
for(;p&&!ch[p][c];p=fa[p])ch[p][c]=np;
if(!p)fa[np]=1;
else
{
int q=ch[p][c];
if(l[p]+1==l[q])fa[np]=q;
else
{
int nq=++cnt;l[nq]=l[p]+1;
memcpy(ch[nq],ch[q],sizeof(ch[q]));
fa[nq]=fa[q];fa[q]=fa[np]=nq;
for(;ch[p][c]==q;p=fa[p])ch[p][c]=nq;
}
}
if(op>=0)sz[np][op]=1;
}
void topo()
{
for(int i=1;i<=cnt;i++)c[l[i]]++;
for(int i=1;i<=cnt;i++)c[i]+=c[i-1];
for(int i=1;i<=cnt;i++)a[c[l[i]]--]=i;
}
void build(){
last=cnt=1;
}
void gao()
{
topo();
for(int i=cnt;i;i--)
for(int j=0;j<=n;j++)
sz[fa[a[i]]][j]+=sz[a[i]][j];
ll ans=0;
for(int i=1;i<=cnt;i++)
{
bool ok=1;
if(!sz[i][0])ok=0;
for(int j=1;j<=n;j++)if(L[j]>sz[i][j]||sz[i][j]>R[j])ok=0;
if(ok)ans+=l[i]-l[fa[i]];
}
printf("%lld\n",ans);
}
}sam;
char s[N];
int main()
{
sam.build();
scanf("%s",s);
n=strlen(s);
for(int i=0;i<n;i++)sam.ins(s[i]-'a',0);
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
sam.ins(26,-1);
scanf("%s%d%d",s,&L[i],&R[i]);
int len=strlen(s);
for(int j=0;j<len;j++)sam.ins(s[j]-'a',i);
}
sam.gao();
return 0;
}
/******************** ********************/
05-11 10:54