题意:定义一个串合法,在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;
}
/******************** ********************/

ABBYY Cup 3.0G3. Good Substrings的更多相关文章

  1. codeforce ABBYY Cup 3.0 - Finals (online version) B2. Shave Beaver! 线段树

    B2. Shave Beaver!   The Smart Beaver has recently designed and built an innovative nanotechnologic a ...

  2. abbyy cup a

    link: http://codeforces.com/contest/331/problem/A2 /* ID: zypz4571 LANG: C++ TASK: abby_a.cpp */ #in ...

  3. ABBYY Cup 3.0 - Finals (online version)

    A 开个数组记录一下 #include <iostream> #include<cstdio> #include<cstring> #include<algo ...

  4. codeforces C1. The Great Julya Calendar 解题报告

    题目链接:http://codeforces.com/problemset/problem/331/C1 这是第一次参加codeforces比赛(ABBYY Cup 3.0 - Finals (onl ...

  5. CodeForces 316c1 Tidying Up

    Tidying Up Time Limit: 4000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Orig ...

  6. [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  7. java高cup占用解决方案

    项目中发现java cpu占用高达百分之四百,查看代码发现有一个线程在空转,拉高了cup while(true){ } 解决方案,循环中加入延迟:Thread.sleep(Time): 总结下排查CP ...

  8. Leetcode: Unique Substrings in Wraparound String

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  9. UVALive 7147 World Cup(数学+贪心)(2014 Asia Shanghai Regional Contest)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...

随机推荐

  1. CSS中的display属性(none,block,inline,inline-block,inherit)

    css中的display属性(none,block,inline,inline-block,inherit) display属性是我们在前端开发中常常使用的一个属性,其中,最常见的有: none bl ...

  2. Struts2 学习

    Struts2简介 1.概念:轻量级的MVC框架,主要解决了请求分发的问题,重心在控制层和表现层.低侵入性,与业务代码的耦合度很低.Struts2实现了MVC,并提供了一系列API,采用模式化方式简化 ...

  3. DNSmasq介绍

    DNSmasq介绍 转载自:http://www.cnblogs.com/demonxian3/p/7472300.html#top 云主机的mac地址由物理机的dnsmasq随机分配,如果要修改ma ...

  4. 2018-2019-1 20189203《Linux内核原理与分析》第八周作业

    第一部分 课本学习 ELF文件(目标文件)格式主要三种: 1)可重定向文件:文件保存着代码和适当的数据,用来和其他的目标文件一起来创建一个可执行文件或者是一个共享目标文件.(目标文件或者静态库文件,即 ...

  5. 笔记-ASP.NET WebApi

    本文是针对ASP.NET WepApi 2 的笔记. Web API 可返回的结果: 1.void 2.HttpResponseMessage 3.IHttpActionResult 4.其他类型 返 ...

  6. ADB工具的使用

    ADB即Android Debug Bridge调试桥,可以用来调试管理Android设备与设备模拟器的状态,比如,在Android设备上运行Shell,在电脑和设备之间互传文件... 那么问题来了. ...

  7. 【软件工程1916|W(福州大学)_助教博客】团队第一次作业成绩公示

    题目 第一次作业 评分准则: 队名(最好能够体现项目内容,要求有亮点与个性):(1分) 拟作的团队项目描述:一句话(中英文不限):(1分) 队员风采:介绍每一名队员,包括成员性格.擅长的技术.编程的兴 ...

  8. python assert断言函数

    python assert断言是声明布尔值必须为真的判定,如果发生异常就说明表达式为假. 可以理解assert断言语句为raise-if-not,用来测试表示式,其返回值为假,就会触发异常. self ...

  9. 每天一个Linux命令 10

    文件处理命令:ln命令名称:ln 命令英文原意:link语法: ln -s [原文件] [目标文件] -s 创建软连接功能描述:生成链接文件 #ln -s /etc/issue /tmp/issue. ...

  10. 利用ueditor保存到mysql数据库时出现乱码

    首先反复检查页面的字符编码,发现使用的都是 utf-8,再次检查数据库编码格式也用的是UTF-8.用format函数进行格式化,还是不起作用,最用把出现乱码的字段的数据类型由BLOB改成MEDIUMT ...