Palindrome

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 433    Accepted Submission(s): 168

Problem Description
Alice like strings, especially long strings. For each string, she has a special evaluation system to judge how elegant the string is. She defines that a string S[1..3n−2](n≥2) is one-and-half palindromic if and only if it satisfies S[i]=S[2n−i]=S[2n+i−2](1≤i≤n).For example, abcbabc is one-and-half palindromic string, and abccbaabc is not. Now, Alice has generated some long strings. She ask for your help to find how many substrings which is one-and-half palindromic.
 
Input
The first line is the number of test cases. For each test case, there is only one line containing a string(the length of strings is less than or equal to 500000), this string only consists of lowercase letters.
 
Output
For each test case, output a integer donating the number of one-and-half palindromic substrings.
 
Sample Input
1
ababcbabccbaabc
 
Sample Output
2

Hint

In the example input, there are two substrings which are one-and-half palindromic strings, $abab$ and $abcbabc$.

 
Source
题意:
给出一个字符串,求有多少这样的子字符串S[1..3n−2](n≥2) 满足:S[i]=S[2n−i]=S[2n+i−2](1≤i≤n),例如 abcbabc 显然n是奇数。
代码:
//要求的就是回文半径相互覆盖的点对有多少,manacher预处理出来奇数长度回文串的中间点的回文半径,用优先队列记录一下到达j点最远能够覆
//盖到的位置,当到达i位置时更新队列(去掉没有用了的点,即到达不了i位置的点),树状数组求i位置前半径中有多少相互覆盖的点并把i加入队列。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MAXN=;
char s[MAXN];
int t,n,p[MAXN<<],a[MAXN<<];
struct cmp{
bool operator () (int &a,int &b)const{
return a+p[a]>b+p[b];
}
};
void manacher()
{
n=strlen(s+);
for(int i=,mx=,id=;i<=n;i++){
p[i]=(mx>i?min(p[id*-i],mx-i):);
while(s[i+p[i]]==s[i-p[i]]) p[i]++;
if(i+p[i]>mx) { mx=i+p[i];id=i; }
}
for(int i=;i<=n;i++) p[i]--;
}
void add(int id,int c)
{
while(id<=MAXN-){
a[id]+=c;
id+=((-id)&id);
}
}
int query(int id)
{
int s=;
while(id){
s+=a[id];
id-=((-id)&id);
}
return s;
}
int main()
{
scanf("%d",&t);
while(t--){
scanf("%s",s+);
manacher();
memset(a,,sizeof(a));
ll ans=;
priority_queue<int,vector<int>,cmp>q;
for(int i=;i<=n;i++){
while(!q.empty()){
int now=q.top();
if(now+p[now]<i){
q.pop();
add(now,-);
}else break;
}
ans+=query(i-)-query(i-p[i]-);
q.push(i);add(i,);
}
printf("%lld\n",ans);
}
return ;
}
 

HDU 6230的更多相关文章

  1. HDU 6230 Palindrome ( Manacher && 树状数组)

    题意 : 给定一个字符串S,问你有多少长度为 n 的子串满足  S[i]=S[2n−i]=S[2n+i−2] (1≤i≤n) 参考自 ==> 博客 分析 : 可以看出满足题目要求的特殊回文子串其 ...

  2. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  4. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  5. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  6. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  7. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  8. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  9. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

随机推荐

  1. Django_rest_framework_渲染器/解析器/路由控制/分页

    目录 渲染器 解析器 路由控制 分页 渲染器 简介 什么是渲染器 根据 用户请求URL 或 用户可接受的类型,筛选出合适的 渲染组件. 渲染器的作用 序列化.友好的展示数据 渲染器配置 首先要在set ...

  2. Notes of Daily Scrum Meeting(11.4)

    Notes of Daily Scrum Meeting 2014年11月4日  星期二  20:30—21:00 团队成员 今日团队任务 当日工作分配额 完成情况 陈少杰 阅读理解代码中底层与数据库 ...

  3. spring冲刺第八天

    昨天使人物成功的在地图上运动,并设计炸弹爆炸效果. 今天使炸弹可以炸死人物并可以炸没砖块,并试着将小怪加入地图. 遇到的问题:现在还没有将小怪加入地图,各个模块的整合是比较麻烦的,我还要在这方面下点功 ...

  4. spring冲刺第二天

    昨天查找了安卓开发的相关资料以及炸弹人游戏的资料. 由于今天课程比较多,只在晚上将安卓开发环境配置完成. 在安装软件时环境配置出现了问题,不过问过同学后成功解决.

  5. java读取properties文件的几种方法

    一.项目中经常会需要读取配置文件(properties文件),因此读取方法总结如下: 1.通过java.util.Properties读取 Properties p=new Properties(); ...

  6. 团队作业之四则运算GUI展示

    一.项目Coding.net原码仓库地址:https://git.coding.net/caoying/Teamwork.git 队员: 卢琪:2016011986 曹滢:2016012102 二.P ...

  7. .NET WinForm下StatusStrip控件如何设置分隔线及部分子控件右对齐

    ssInfo.LayoutStyle = ToolStripLayoutStyle.StackWithOverflow;//StatusStrip 控件 tsslUpdate.Alignment = ...

  8. (三)使用Jmeter模拟300个用户登录

    1.首先在系统中创建300个用户(在这里使用 pl/sql 进行循环创建): 代码如下: --先对原先的表进行备份 :CREATE TABLE sys_user_bak AS SELECT * FRO ...

  9. gitlab账号注册及分组

    .开启注册邮箱验证 admin area -->setting-->Sign-up restrictions-->勾选Send confirmation email on sign- ...

  10. C#基础知识(base、this、new、override、abstract、virtual、static)

    前言 本文主要来讲解一下C#中,自己觉得掌握的不怎么样或者用的不多,不太熟悉的关键字,主要包括base.this.new.override.abstract.virtual以及针对static字段和s ...