BZOJ 2342 [Shoi2011]双倍回文(manacher+堆+set)
题意

N<=500000
题解

维护一个set可以用堆来解决。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
using namespace std;
const int N=;
int str[N*],m,p[N*];
int n,f[N],now,ans;
char s[N];
struct hhh{
int l,r;
bool operator <(const hhh &a)const{
return a.r<r;
}
}c[N];
set<int> se;
priority_queue<hhh> q;
void init(){
str[]=str[]='#';
for(int i=;i<=n;i++){
str[i*]=s[i];
str[i*+]='#';
}
m=n*+;
}
void manacher(){
int mx=,id;
for(int i=;i<=m;i++){
if(mx>i)p[i]=min(p[id-(i-id)],id+p[id]-i);
else p[i]=;
while(str[i-p[i]]==str[i+p[i]])p[i]++;
if(i+p[i]->mx)mx=i+p[i]-,id=i;
}
}
int main(){
scanf("%d",&n);
scanf("%s",s+);
init();
manacher();
for(int i=;i<=n;i++){
f[i]=p[i*+]/;
c[i].l=i;
c[i].r=i+f[i];
}
for(int i=;i<=n;i++){
if(i-+f[i-]>=i){
se.insert(i-);
q.push(c[i-]);
}
while(!q.empty()&&q.top().r<i){
se.erase(q.top().l);
q.pop();
}
set<int>::iterator it=se.lower_bound(i-f[i]/);
if(it!=se.end()){
ans=max(ans,(i-*it)*);
}
}
printf("%d",ans);
return ;
}
BZOJ 2342 [Shoi2011]双倍回文(manacher+堆+set)的更多相关文章
- bzoj 2342: [Shoi2011]双倍回文 -- manacher
2342: [Shoi2011]双倍回文 Time Limit: 10 Sec Memory Limit: 128 MB Description Input 输入分为两行,第一行为一个整数,表示字符 ...
- BZOJ 2342: [Shoi2011]双倍回文 [Manacher + set]
题意: 求最长子串使得它有四个相同的回文串SSSS相连组成 枚举中间x 找右边的中间y满足 y-r[y]<=x y<=x+r[x]/2 用个set维护 注意中间只能是# #include ...
- 2018.06.30 BZOJ 2342: [Shoi2011]双倍回文(manacher)
2342: [Shoi2011]双倍回文 Time Limit: 10 Sec Memory Limit: 128 MB Description Input 输入分为两行,第一行为一个整数,表示字符串 ...
- BZOJ 2342: [Shoi2011]双倍回文 马拉车算法/并查集
2342: [Shoi2011]双倍回文 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1123 Solved: 408 题目连接 http://w ...
- Manacher || BZOJ 2342: [Shoi2011]双倍回文 || Luogu P4287 [SHOI2011]双倍回文
题面:[SHOI2011]双倍回文 题解:具体实现时,就是在更新mr时维护前半段是回文串的最长回文串就好了 正确性的话,因为到i时如果i+RL[i]-1<=mr,那么答案肯定在i之前就维护过了: ...
- BZOJ 2342 [Shoi2011]双倍回文(manacher+并查集)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2342 [题目大意] 记Wr为W串的倒置,求最长的形如WWrWWr的串的长度. [题解] ...
- BZOJ 2342 [SHOI2011]双倍回文 (回文自动机)
题目大意:略 先建出$PAM$ 因为双倍回文串一定是4的倍数,所以找出$PAM$里所有$dep$能整除4的节点 看这个串是否存在一个回文后缀,长度恰好为它的一半,沿着$pre$链往上跳就行了 暴跳可能 ...
- BZOJ 2342 [Shoi2011]双倍回文(Manacher)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2342 题意:求最长子串使得它有四个相同的回文串SSSS相连组成. 首先跑一边Manach ...
- bzoj 2342 [Shoi2011]双倍回文(manacher,set)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2342 [题意] 求出形如w wR w wR的最长连续子串. [思路] 用manache ...
随机推荐
- Lambda 表达式-即匿名函数
拉姆达值(Lambda),希腊字母表示为Λ,指与真空的空间有关的能量或暗能量. 代表转换的常量.或者转换本身. Lambda 表达式 Lambda 表达式”是一个匿名函数,可以包含表达式和语句 ...
- ZBrush软件如何编辑物体
新手在刚接触ZBrush®的时候,想要选中模型进行编辑,有时怎么都选不中,当再次画的时候只能在边上新建一个,还是不能进行编辑,遇到类似问题,你是如何解决的,本文将为您讲解ZBrush中怎么选中物体并进 ...
- npm run eject 命令后出现This git repository has untracked files or uncommitted changes错误
npm run eject 暴露隐藏的文件,不可逆 结果出现下面的问题 This git repository has untracked files or uncommitted changes: ...
- vue项目 预览照片的插件 v-viewer
查看图片主要使用的旋转.翻转.缩放.上下切换.键盘操作等功能都有. 1.首先是安装 npm install v-viewer --save 2.安装完在main.js里面引用(还要记得引用它的css样 ...
- 博客模板更新CSS
采用了作者#a的模板BlueSky进行了些许修改 在原有基础上加了三个样式,使页面显示风格统一些 #home{ background-color:#fff; } #main{ background-c ...
- 安装idea
1.下载idea https://www.jetbrains.com/idea/download/#section=linux 2.解压 sudo tar -zxvf ideaIC-2018.3.2 ...
- 归档 SCP SFTP RSYNC(数据同步)
tar 选项 目标文件 源文件(1 2 3) tar cf **.tar file1 file2 file3 (默认情况下 cf选项只有归档没有压缩) tar xf 从归档中提取 创建tar的存档 ...
- Nuxt开发经验分享
Nuxt开发经验分享 本文章基于starter-template模板进行讲解,面向有vue-cli开发经验的宝宝 vue init nuxt-community/starter-template ...
- POI实现Excel2003插入多张图片
POI的操作Excel时,不可避免有操作图片的处理.怎么插入图片呢?网上也有不少介绍. 下面的代码是向Excel中插入多张图片的例子: public static void main(String[] ...
- 使用hbase遇到的问题
1.在使用hbase的时候 有很多问题,其中一个 使用sqoop import 从mysql 向hbase导入数据,报错:Error: java.lang.RuntimeException: Coul ...