BZOJ 2342 Manacher
思路:
首先用manacher可以求出以i和i+1中间为对称轴,最长回文串能扩增的长度p[i]。
然后4*(y-x)能更新答案,当且仅当y≤x+p[x]/2且y-p[y]≤x。
按i-p[i]将所有点排序,依次插入set中,查询x+p[x]/2的前驱更新答案,时间复杂度O(n*logn)。
——AaronPolaris
//By SiriusRen
#include <set>
#include <cstdio>
#include <algorithm>
using namespace std;
#define N 555555
set<int>st;
int l,ans,p[N],mx,id,tp;char s[N];
struct Node{int x,y;}node[N];
bool cmp(Node a,Node b){return a.x<b.x;}
int main(){
scanf("%d%s",&l,s+1),s[0]='%';
for(int i=1;i<=l;i++){
if(mx>i)p[i]=min(p[id*2-i],mx-i);
else p[i]=0;
while(s[i+p[i]+1]==s[i-p[i]])p[i]++;
if(i+p[i]>mx)mx=i+p[i],id=i;
}
for(int i=1;i<=l;i++){
node[i].x=i-p[i],node[i].y=i;
}sort(node+1,node+1+l,cmp);
for(int i=1;i<=l;i++){
while(tp<l&&node[tp+1].x<=i)st.insert(node[++tp].y);
ans=max(ans,(*--st.lower_bound(i+p[i]/2+1)-i)*4);
}printf("%d\n",ans);
}
BZOJ 2342 Manacher的更多相关文章
- 【题解】Casting Spells LA 4975 UVa 1470 双倍回文 SDOI 2011 BZOJ 2342 Manacher
首先要吐槽LRJ,书上给的算法标签是“有难度,需要结合其他数据结构”,学完Manacher才发现几乎一裸题 题目的意思是问原串中有多少个wwRwwR这样的子串,其中wR表示w的反串 比较容易看出来,w ...
- BZOJ 2342 回文串-Manacher
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2342 思路:先跑一遍Manacher求出p[i]为每个位置为中心的回文半径,因为双倍回文串 ...
- BZOJ 2342 双倍回文(manacher算法)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2342 题意:定义双倍回文串为:串的长度为4的倍数且串的前一半.后一半.串本身均是回文的. ...
- bzoj 2342 [Shoi2011]双倍回文(manacher,set)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2342 [题意] 求出形如w wR w wR的最长连续子串. [思路] 用manache ...
- bzoj 2342: [Shoi2011]双倍回文 -- manacher
2342: [Shoi2011]双倍回文 Time Limit: 10 Sec Memory Limit: 128 MB Description Input 输入分为两行,第一行为一个整数,表示字符 ...
- BZOJ 2342 [Shoi2011]双倍回文(manacher+并查集)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2342 [题目大意] 记Wr为W串的倒置,求最长的形如WWrWWr的串的长度. [题解] ...
- BZOJ 2342 [Shoi2011]双倍回文(Manacher)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2342 题意:求最长子串使得它有四个相同的回文串SSSS相连组成. 首先跑一边Manach ...
- 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 输入分为两行,第一行为一个整数,表示字符串 ...
随机推荐
- UI_UIImagePickerController(读取图片)
创建图片 #pragma mark - 创建 photoImageView - (void)createphotoImageView { self.photoImageView = [[UIImage ...
- android官网被封掉了,仅仅好用这个站点进谷歌了!嘎嘎
http://developer.android.com/sdk/index.html 这个能够进去.可是必须是搜狐 .360,uc都不用特意FQ http://173.1 ...
- leetcode 题解 || Longest Common Prefix 问题
problem: Write a function to find the longest common prefix string amongst an array of strings. 寻找 0 ...
- iOS UI08_UITableView
(http://img.blog.csdn.net/20150808103801391) // // MainViewController.m // UI08_UITableView // // Cr ...
- xBIM 基础04 日志操作
系列目录 [已更新最新开发文章,点击查看详细] xBIM使用Log4Net来记录异常不适合的处理错误和警告.它在xBIM几何引擎中被大量使用来记录所有几何错误.如果您的文件看起来不太正确,则应 ...
- Windows版Redis如何使用?(单机)
使用Windows版Redis 1.下载Windows版本的Redis 2.在redis目录里创建redis.conf ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...
- web语义化理解
含义: Web语义化是指使用语义恰当的标签,使页面有良好的结构,页面元素有含义,能够让人和搜索引擎都容易理解. 为什么要web语义化?如今互联网都到了web2.0的时代了,HTML语言在不断的进化并发 ...
- python 3.x 学习笔记8 (os模块及xml修改)
1.os模块操作 os.getcwd(): # 查看当前所在路径. os.listdir(path): ...
- SQLServer 错误: 15404,维护计划无法执行
错误症状: D:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG下面的ERROELOG,用文本打,查看运行维维计划不成功是生成的错误日志详细信 ...
- There is no 'root'@'%' registered解决
把别人机器上的MYSQL中的一个数据库导出来,生成了一个.sql的文件 在我的机器上导入这个.sql文件之后,在数据库连接时出现了如下错误: “There is no 'root'@'%' ...