题意:给你一个字符串s有一些位置被ban了,字符串t的价值是|t|*t在s中出现次数而且终点没有被ban.问你最大的价值是多少

题解:很明显t是s子串,建个sam,对于sam中每个位置,我们需要删除中点被ban的次数,只需要在sam上走一遍,到被ban的点时需要更新fa链,打个标记,根据topo序差分即可,和sz求法一样

//#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=200000+10,maxn=100000+10,inf=0x3f3f3f3f; char s[N],p[N];
struct SAM{
int last,cnt;
int ch[N<<1][26],fa[N<<1],l[N<<1],sz[N<<1],d[N<<1];
int a[N<<1],c[N<<1];
void ins(int c){
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;
}
}
sz[np]=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;
for(int i=0;s[i];i++)ins(s[i]-'a');
topo();
int now=1;
for(int i=0;p[i];i++)
{
now=ch[now][s[i]-'a'];
if(p[i]=='1')d[now]++;
}
for(int i=cnt;i;i--)sz[fa[a[i]]]+=sz[a[i]],d[fa[a[i]]]+=d[a[i]];
ll ans=0;
for(int i=2;i<=cnt;i++)ans=max(ans,1ll*l[i]*(sz[i]-d[i]));
printf("%lld\n",ans);
}
}sam;
int main()
{
int n;scanf("%d%s%s",&n,s,p);
sam.build();
return 0;
}
/******************** ********************/

edu30F. Forbidden Indices的更多相关文章

  1. 【CF873F】Forbidden Indices 后缀自动机

    [CF873F]Forbidden Indices 题意:给你一个串s,其中一些位置是危险的.定义一个子串的出现次数为:它的所有出现位置中,不是危险位置的个数.求s的所有子串中,长度*出现次数的最大值 ...

  2. Codeforces 873F Forbidden Indices 字符串 SAM/(SA+单调栈)

    原文链接https://www.cnblogs.com/zhouzhendong/p/9256033.html 题目传送门 - CF873F 题意 给定长度为 $n$ 的字符串 $s$,以及给定这个字 ...

  3. CF873F 【Forbidden Indices】

    还有这么板子的题? 和你谷上后缀自动机的板子基本一样,区别就是之后这个位置是\(0\)才计入贡献 代码 #include<iostream> #include<cstdio> ...

  4. CodeForces 873F Forbidden Indices 后缀数组

    忘了当时怎么做的了,先把代码贴上,保存一下后缀数组模板. #include <cstdio> #include <cstring> #include <algorithm ...

  5. CF873F Forbidden Indices 后缀自动机+水题

    刷刷水~ Code: #include <cstdio> #include <cstring> #include <algorithm> #define N 200 ...

  6. Educational Codeforces Round 30

    Educational Codeforces Round 30  A. Chores 把最大的换掉 view code #pragma GCC optimize("O3") #pr ...

  7. Kibana 创建索引 POST 403 (forbidden) on create index

    一.问题描述: Kibana创建索引:kibana > management > index patterns > create index pattern 索引名称: mercha ...

  8. 遇到 HTTP 错误 403.14 - Forbidden?

    打开 http://localhost:1609 报错: HTTP 错误 403.14 - Forbidden Web 服务器被配置为不列出此目录的内容 解决方案一:设置默认首页 在 Web.conf ...

  9. Forbidden You don't have permission to access / on this server PHP

    在新安装的谷歌游览器里,打不了PHP网站了,错误显示: Forbidden You don't have permission to access / on this server. 原因还是配置权限 ...

随机推荐

  1. 【转载】word2vec原理推导与代码分析

    本文的理论部分大量参考<word2vec中的数学原理详解>,按照我这种初学者方便理解的顺序重新编排.重新叙述.题图来自siegfang的博客.我提出的Java方案基于kojisekig,我 ...

  2. favorite learning link

    Xpath https://www.cnblogs.com/chenshaoping/p/5540434.html Awk Sort https://www.cnblogs.com/chengmo/a ...

  3. 初学Vue 遇到Module not found:Error:Can`t resolve 'less-loader' 问题

    学习vue时,导入一个子组件时遇到Module not found:Error:Can`t resolve 'less-loader' 问题,实际上时在子组件中的样式里加了这么个代码 <styl ...

  4. 004-mac下Java6与Java8 安装

    一.Java6安装 官方下载下载地址:http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-down ...

  5. 流控制、FlowControl

    这个选项基本上所有网卡都会有,但是叫法会有些差别,比如Realtek网卡叫做流控制,Intel网卡叫做流程控制,还有一些网卡选项干脆是英文的,叫做FlowControl,很多交换机上也有这个功能,也叫 ...

  6. idea 无法找到或加载主类

  7. PowerBI新功能: 自定义数据连接器(Data Connector)

    你是不是觉得原有的数据连接器(Data Connector)列表,就像女人的衣柜,总少那么一件你想要的呐? 现在,你的救星来了!你可以自己造一个了! Power BI的数据连接器(Data Conne ...

  8. Linux平台 Oracle 18c RAC安装Part2:GI配置

    三.GI(Grid Infrastructure)安装 3.1 解压GI的安装包 3.2 安装配置Xmanager软件 3.3 共享存储LUN的赋权 3.4 使用Xmanager图形化界面配置GI 3 ...

  9. IP-v4&IP-v6

    IPv6与IPv4区别: 1:IPv6的地址空间更大.IPv4中规定IP地址长度为32,即有2^32-1个地址: 而IPv6中IP地址的长度为128,即有2^128-1个地址. 2.IPv6的路由表更 ...

  10. [Luogu]A%BProblem——线性筛素数与前缀和

    题目描述 题目背景 题目名称是吸引你点进来的[你怎么知道的] 实际上该题还是很水的[有种不祥的预感..] 题目描述 区间质数个数 输入输出格式 输入格式: 一行两个整数 询问次数n,范围m接下来n行, ...