题目大意: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. Alpha冲刺总结

    团队成员 陈家权 031502107 赖晓连 031502118 雷晶 031502119 林巧娜 031502125 庄加鑫 031502147 一.项目预期计划及现实进展 项目预期计划 现实进展 ...

  2. C语言函数2

    一.PTA实验作业 6-3 使用函数判断完全平方数: 1. 本题PTA提交列表: 2. 设计思路: 3.本题调试过程碰到问题及PTA提交列表情况说明: 1.一开始考虑让输入值N去整除一个循环变量i,i ...

  3. Socket程序从windows移植到linux下需要注意的

    )头文件 windows下winsock.h或winsock2.h linux下netinet/in.h(大部分都在这儿),unistd.h(close函数在这儿),sys/socket.h(在in. ...

  4. 2018上C语言程序设计(高级)作业- 第2次作业

    作业要求一 提交截图: 6-7: 6-8: 6-9: 7-1: 作业要求二 题目6-7删除字符中数字字符 1.设计思路: (1)第一步:本题要求是删除字符中的数字字符,我的主要思路是通过数组遍历若遇到 ...

  5. 400多个开源项目以及43个优秀的Swift开源项目-Swift编程语言资料大合集

    Swift 基于C和Objective-C,是供iOS和OS X应用编程的全新语言,更加高效.现代.安全,可以提升应用性能,同时降低开发难度. Swift仍然处于beta测试的阶段,会在iOS 8发布 ...

  6. 201421123042 《Java程序设计》第9周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 2. 书面作业 本次作业题集集合 1. List中指定元素的删除(题集题目) 1.1 实验总结.并回答:列举至 ...

  7. bzoj千题计划252:bzoj1095: [ZJOI2007]Hide 捉迷藏

    http://www.lydsy.com/JudgeOnline/problem.php?id=1095 点分树+堆 请去看 http://www.cnblogs.com/TheRoadToTheGo ...

  8. Huginn实现自动通过slack推送豆瓣高分电影

    博客搬迁至https://blog.wangjiegulu.com RSS订阅:https://blog.wangjiegulu.com/feed.xml 原文链接:https://blog.wang ...

  9. Map集合、散列表、红黑树介绍

    前言 声明,本文用得是jdk1.8 前面已经讲了Collection的总览和剖析List集合: Collection总览 List集合就这么简单[源码剖析] 原本我是打算继续将Collection下的 ...

  10. Docker学习笔记 - 在运行中的容器内启动新进程

    docker psdoker top dc1 # 容器情况# 在运行中的容器内启动新进程docker exec [-d] [-i] [-t] 容器名 [command] [args]docker ex ...