ABBYY Cup 3.0G3. Good Substrings
题意:定义一个串合法,在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的更多相关文章
- 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 ...
- abbyy cup a
link: http://codeforces.com/contest/331/problem/A2 /* ID: zypz4571 LANG: C++ TASK: abby_a.cpp */ #in ...
- ABBYY Cup 3.0 - Finals (online version)
A 开个数组记录一下 #include <iostream> #include<cstdio> #include<cstring> #include<algo ...
- codeforces C1. The Great Julya Calendar 解题报告
题目链接:http://codeforces.com/problemset/problem/331/C1 这是第一次参加codeforces比赛(ABBYY Cup 3.0 - Finals (onl ...
- CodeForces 316c1 Tidying Up
Tidying Up Time Limit: 4000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Orig ...
- [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- java高cup占用解决方案
项目中发现java cpu占用高达百分之四百,查看代码发现有一个线程在空转,拉高了cup while(true){ } 解决方案,循环中加入延迟:Thread.sleep(Time): 总结下排查CP ...
- Leetcode: Unique Substrings in Wraparound String
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- UVALive 7147 World Cup(数学+贪心)(2014 Asia Shanghai Regional Contest)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...
随机推荐
- Windows 10 更改系统文字大小
一. Win + R 进入Regedit: 二. 定位到下图的位置: 三. 选中一个项目,右键,选中修改二进制,打开后如下图: 四. 1.这里,0000一行中的第一位,对应了图形界面设置中的字体大小. ...
- Linux之cat的使用
基本介绍 工作原理 从标准输入读入要 cat 的文件列表,然后逐个打开,读入文件内容,再将内容输出到标准输出上. 使用场景 一次显示整个文件 从键盘创建一个文件 将几个文件合并为一个文件 将一个或多个 ...
- python练习题-day13
1.获取移动平均值 def wrapper(fun): def inner(*args,**kwargs): ret=fun(*args,**kwargs) ret.__next__() return ...
- Redis入门到高可用(十五)—— HyperLogLog
一.简介 二.API Demo 三.使用经验
- python框架之Django(10)-Form组件
介绍 我们之前在HTML页面中利用form表单向后端提交数据时,都会写一些获取用户输入的标签并且用form标签把它们包起来.与此同时我们在好多场景下都需要对用户的输入做校验,比如校验用户是否输入,输入 ...
- python基础之 while 逻辑运算符 格式化输出等
1.while循环 while 条件: 循环体 while 条件: 循环体 else: 循环体 重点: 当条件为真的时候,就进入循环体,从上到下依次执行,执行完最后一条语句时,while并不是直接退出 ...
- 2.1 Html
一.Head中常用标签 <head>元素出现在文档的开头部分,会书写一些和浏览器中的配置信息. <head>与</head>之间的内容不会在浏览器的文档窗口显示,但 ...
- Lua 求当前月份的最大天数
[1]实现代码 -- 第一种方式:简写 , day = })) print('The first way result : dayAmount = ' .. dayAmount) -- 第二种方式:分 ...
- Windwos Live Writer插件指南
Windows Live Writer 即(WLW) 是一个免费的桌面应用程序,可以用于发布博客. 官网下载地址:https://www.microsoft.com/zh-CN/download/de ...
- Linux基础命令---lpr打印文件
lpr lpr指令用来打印文件,如果没有指定文件名,那么从标准输入读取内容.CUPS提供了许多设置默认目标的方法.首先查询“LPDEST”和“PRINTER”环境变量.如果没有设置,则使用lpopti ...