题目大意:n个字符串,支持修改一个位置上的字符串和查询一个区间的子区间中长度乘LCP的最大值,输入字符数和询问数不超过10^5。

做法:求出相邻的LCP长度,区间LCP等于区间最小值,查询分几种情况考虑,一种只有一个串,线段树维护长度最大值即可;若有若干个串,设一个阈值k,若答案的LCP<=k,对于小等k的每一个i,若一个位置的相邻LCP大等i,设为1,否则设为0,即求区间最长连续1,每种i开一棵线段树维护即可;若LCP>k,我们把相邻LCP长度超过k的位置存进set,查询的时候拿出来,直接建笛卡尔树计算答案,由于字符总数有限,这样的位置不会超过L/k个。总时间复杂度为O(nklogn+nL/k),适当调整k,时间复杂度为O(n(nlogn)^0.5)。

代码:

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<queue>
#include<map>
#include<set>
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
#define MN 100000
#define N 131072
#define K 50
struct node{int l,r,u,mx;}T[K+][N*+];
node operator+(const node&a,const node&b)
{
return (node){a.l+a.u*b.l,b.r+b.u*a.r,a.u*b.u,max(max(a.mx,b.mx),a.r+b.l)};
}
string s[MN+];
int t[N*+],v[MN+],a[MN+],an,Z[MN+],zn,L[MN+],R[MN+],ans,S[MN+];
set<int> st;
void change(int k,int x){for(t[k+=N]=x;k>>=;)t[k]=max(t[k<<],t[k<<|]);}
int query(int l,int r)
{
int res=;
for(l+=N-,r+=N+;l^r^;l>>=,r>>=)
{
if(~l&)res=max(res,t[l+]);
if( r&)res=max(res,t[r-]);
}
return res;
}
void change(node*t,int k,node x){for(t[k+=N]=x;k>>=;)t[k]=t[k<<]+t[k<<|];}
node Query(node*t,int l,int r)
{
node L,R;int ul=,ur=;
for(l+=N-,r+=N+;l^r^;l>>=,r>>=)
{
if(~l&)L=ul?L+t[l+]:(ul=,t[l+]);
if( r&)R=ur?t[r-]+R:(ur=,t[r-]);
}
return ul?ur?L+R:L:R;
}
void renew(int x)
{
cin>>s[x];change(x,s[x].size());
if(v[x]>K)st.erase(x);if(v[x+]>K)st.erase(x+);
for(v[x]=;v[x]<s[x].size()&&v[x]<s[x-].size()&&s[x][v[x]]==s[x-][v[x]];)++v[x];
for(v[x+]=;v[x+]<s[x].size()&&v[x+]<s[x+].size()&&s[x][v[x+]]==s[x+][v[x+]];)++v[x+];
if(v[x]>K)st.insert(x);if(v[x+]>K)st.insert(x+);
node a=(node){,,,},b=(node){,,,};
for(int i=;i<=K;++i)change(T[i],x,v[x]<i?a:b),change(T[i],x+,v[x+]<i?a:b);
}
void dfs(int x)
{
S[x]=;
if(L[x])dfs(L[x]),S[x]+=S[L[x]];
if(R[x])dfs(R[x]),S[x]+=S[R[x]];
ans=max(ans,v[x]*(S[x]+));
}
int p(const set<int>::iterator&i){return i!=st.end()?*i:MN+;}
int main()
{
int n,m,i,l,r,z;
n=read();m=read();
for(i=;i<=n;++i)renew(i);
while(m--)
if(read()==)
{
l=read();r=read();
ans=query(l,r);
if(l<r)for(i=;i<=K;++i)z=Query(T[i],l+,r).mx,ans=max(ans,i*(z?z+:));
set<int>::iterator it=st.upper_bound(l);
for(z=p(it);z<=r;)
{
for(a[an=]=z;(z=p(++it))<=r&&z==a[an]+;)a[++an]=z;
for(i=,zn=;i<=an;++i)
{
L[a[i]]=R[a[i]]=;
while(zn&&v[a[i]]<v[a[Z[zn]]])L[a[i]]=a[Z[zn--]];
R[a[Z[zn]]]=a[i];Z[++zn]=i;
}
dfs(a[Z[]]);
}
printf("%d\n",ans);
}
else renew(read());
}

[Codeforces]862F - Mahmoud and Ehab and the final stage的更多相关文章

  1. Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)

    Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...

  2. Codeforces 862A Mahmoud and Ehab and the MEX

    传送门:CF-862A A. Mahmoud and Ehab and the MEX time limit per test 2 seconds memory limit per test 256 ...

  3. Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)

    Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...

  4. Codeforces 862B - Mahmoud and Ehab and the bipartiteness

    862B - Mahmoud and Ehab and the bipartiteness 思路:先染色,然后找一种颜色dfs遍历每一个点求答案. 代码: #include<bits/stdc+ ...

  5. Codeforces 862C - Mahmoud and Ehab and the xor

    862C - Mahmoud and Ehab and the xor 思路:找两对异或后等于(1<<17-1)的数(相当于加起来等于1<<17-1),两个再异或一下就变成0了 ...

  6. Codeforces 862D. Mahmoud and Ehab and the binary string (二分)

    题目链接:Mahmoud and Ehab and the binary string 题意: 一道交互题,首先给出一个字符串的长度l.现在让你进行提问(最多15次),每次提问提出一个字符串,会返回这 ...

  7. codeforces E. Mahmoud and Ehab and the function(二分+思维)

    题目链接:http://codeforces.com/contest/862/problem/E 题解:水题显然利用前缀和考虑一下然后就是二分b的和与-ans_a最近的数(ans_a表示a的前缀和(奇 ...

  8. codeforces D. Mahmoud and Ehab and the binary string(二分)

    题目链接:http://codeforces.com/contest/862/submission/30696399 题解:这题一看操作数就知道是二分答案了.然后就是怎么个二分法,有两种思路第一种是找 ...

  9. CodeForces 959E Mahmoud and Ehab and the xor-MST (MST+找规律)

    <题目链接> 题目大意: 给定一个数n,代表有一个0~n-1的完全图,该图中所有边的边权为两端点的异或值,求这个图的MST的值. 解题分析: 数据较大,$10^{12}$个点的完全图,然后 ...

随机推荐

  1. beta冲刺7-咸鱼

    前言:最后一篇惹.明天就是正式交差了.有点慌-- 昨天的未完成: 用户试用+测评 输入部分的正则式判定 今天的工作: 登陆界面修改 我的社团显示效果优化 部分信息注册后锁定无法修改 其他部分功能优化 ...

  2. 20145237 实验二 “Java面向对象程序设计”

    20145237 实验二 “Java面向对象程序设计” 实验内容 • 理解并掌握面向对象三要素:封装.继承.多态 • 初步掌握UML建模 • 熟悉S.O.L.I.D原则 • 使用TDD设计实现复数类 ...

  3. class AClass<E extends Comparable>与class AClass<E extends Comaprable<E>>有什么区别?

    new ArrayList<>()与new ArrayList()一样 都是为了做限定用的 如果不了解你可以看API 这个Comparable里面有一个方法compareTo(T o) 如 ...

  4. 第四十三条:返回零长度的数组或者集合,而不是null

    如果一个方法的返回值类型是集合或者数组 ,如果在方法内部需要返回的集合或者数组是零长度的,也就是没有实际对象在里面, 我们也应该放回一个零长度的数组或者集合,而不是返回null.如果返回了null,客 ...

  5. vue jquery js 获取当前时间本周的第一天 和 本月的第一天

    交互的时候传输数据 后台要求这样的数据 直接上代码 这是我找度姨要的  附上链接  https://www.cnblogs.com/wasabii/p/7756560.html 它里面有本季度第一天  ...

  6. phalcon环境的搭建和dll扩展下载与选择

    phalcon需要下载一个扩展的dll文件才能运行项目 其中需要注意dll放在一个php扩展目录中windows下php/ext/,还需要在两个Php.ini文件中增加扩展说明,一般只需要更改 D:\ ...

  7. babel基本用法

    babel-cli babel-cli是本地使用编译js文件 1.安装: cnpm i babel-cli babel-preset-env -D 2.配置packjson: "script ...

  8. WIN7 局域网共享打印机每次电脑重启后必须登录密码重新连接问题修复

    第一步,WIN+R(或者开始->附件->运行)输入gpedit或gpedit.msc 进入 第二步:把这几个拒绝的Guest给删除掉,也可以只删除""拒绝从王洛访问这台 ...

  9. Python内置函数(6)——round

    英文文档: round(number[, ndigits]) Return the floating point value number rounded to ndigits digits afte ...

  10. Dojo API中文 Dojo内容模块概览,初学者

    官网:http://dojotoolkit.org/reference-guide/1.10/dojo/index.html#dojo-dojo的翻译 dojo 内容: dojo dojo/dojo ...