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 ...
随机推荐
- 2015 Objective-C 新特性
Overview 自 WWDC 2015 推出和开源 Swift 2.0 后,大家对 Swift 的热情又一次高涨起来,在羡慕创业公司的朋友们大谈 Swift 新特性的同时,也有很多像我一样工作上依然 ...
- Kattis - mixedfractions
Mixed Fractions You are part of a team developing software to help students learn basic mathematics. ...
- MobilNnet
一.参数数量和理论计算量 1.定义 参数数量(params):关系到模型大小,单位通常为M,通常参数用 float32 表示,也就是每个参数占4个字节,所以模型大小是参数数量的 4 倍 理论计算量(F ...
- Day 04 [与用户交互,格式化输出,基本运算符]
Python 的与用户交互 name=input("请输入姓名:") height=input('请输入身高:') weight=input('请输入体重:') 在python3中 ...
- NotFoundHttpException
报错:NotFoundHttpException 这种一般都是路由配置错误
- [读书笔记] Python 数据分析 (八)画图和数据可视化
ipython3 --pyplot pyplot: matplotlib 画图的交互使用环境
- ubuntu 12.04下安装Qt出现cannot execute binary file的解决方案
最近在ubuntu 12.04下安装QT的过程中,遇到一个问题. ./qt-opensource-linux-x64-5.7.0.run出现了bash: ./qt-opensource-linux-x ...
- VUE:内置指令与自定义指令
VUE:内置指令与自定义指令 常用的内置指令 1)v:text 更新元素的 textContent 2)v-html 更新元素的 innerHTML 3)v-if 如果为true,当前标签才会输出到页 ...
- STM32 Cubemx 输出可调频率与占空比的PWM
这里就不对STM32的PWM进行讲解了,想要了解的可以百度一下,这里主要说怎么实现. 1.建立工程,我选的是STM32F103zet6芯片,选择定时器的PWM功能 2.配置时钟,我这里配的是内部时钟, ...
- 移动端ios兼容问题
IOS系统bug: 1)input无法输入的问题: -webkit-user-select:none;改成-webkit-user-select:auto: 2)滚动不流畅(overflow-y:au ...