2019杭电多校HDU6599 I Love Palindrome String

题目链接

I Love Palindrome String
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 582 Accepted Submission(s): 220
Problem Description
You are given a string S=s1s2…s|S| containing only lowercase English letters. For each integer i∈[1,|S|] , please output how many substrings slsl+1…sr satisfy the following conditions:
∙ r−l+1 equals to i.
∙ The substring slsl+1…sr is a palindrome string.
∙ slsl+1…s⌊(l+r)/2⌋ is a palindrome string too.
|S| denotes the length of string S.
A palindrome string is a sequence of characters which reads the same backward as forward, such as madam or racecar or abba.

Input
There are multiple test cases.
Each case starts with a line containing a string S(1≤|S|≤3×105) containing only lowercase English letters.
It is guaranteed that the sum of |S| in all test cases is no larger than 4×106.

Output
For each test case, output one line containing |S| integers. Any two adjacent integers are separated by a space.

Sample Input
abababa

Sample Output
7 0 0 0 3 0 0

Source
2019 Multi-University Training Contest 2

题意:
给你一个字符串,求对于每一个长度i-len,问有多少个,回文串的前一半也是回文串
思路:
回文树裸题,用hash判断前后两部分是否相同

#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#include <string>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define pd(n) printf("%d\n", (n))
#define pdd(n,m) printf("%d %d", n, m)
#define pld(n) printf("%lld\n", n)
#define pldd(n,m) printf("%lld %lld\n", n, m)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mm(a,n) memset(a, n, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mod(x) ((x)%MOD)
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const int MAXN = 100005 ;
const int N = 3e5+10;
const ull hash1 = 201326611;
const ull hash2 = 50331653;
inline int read()
{int ret = 0, sgn = 1;char ch = getchar();while(ch < '0' || ch > '9'){if(ch == '-') sgn = -1;ch = getchar();}while (ch >= '0' && ch <= '9'){ret = ret*10 + ch - '0';ch = getchar();}return ret*sgn;
}
char str[N];
ll ret[N];
ull ha[N], pp[N];
ull getha(int l, int r)
{if (l == 0) return ha[r];return ha[r] - ha[l - 1] * pp[r - l + 1];
}
bool check(int l, int r)
{int len = r - l + 1;int mid = (l + r) >> 1;if (len & 1) return getha(l, mid) == getha(mid, r);else return getha(l, mid) == getha(mid + 1, r);
}
struct PTree
{int nxt[N][26]; //i节点对应的回文串在两边各加一个字符后变成的节点编号int fail[N]; //fail[i]表示的串是i的最长后缀回文串int cnt[N]; //表示这个串出现过几次int num[N]; //节点i这个串的后缀有多少是回文的int len[N]; //节点i表示的回文串的长度int S[N]; //S[i]是第i次添加的字符int last; //以n结束的最长回文串所在的节点int n; //目前添加的字符个数int p; //下一个新建节点的标号int id[N];inline int newnode(int l){//新建节点for(int i = 0; i < 26; ++i) nxt[p][i] = 0;cnt[p] = num[p] = 0;len[p] = l;return p++;}inline void init(){p = 0;newnode(0);newnode(-1);last = n = 0;S[n] = -1;fail[0] = 1;}inline int get_fail(int x){while(S[n - len[x] - 1] != S[n]) x = fail[x];return x;/*新加进来一个字符时,只有Str[Nnow−len[x]−1]=Str[Nnow]Str[Nnow−len[x]−1]=Str[Nnow]我们才可以说是能构成一个新的回文串(构成回文节点唯一方法,就是在已有基础上找一个节点,在其两端各拓展一个字符,也就是我们所说的找到一个x,使式子成立)。于是我们就可以去不停给last跑fail,直到满足条件。*/}inline void add(int c)//加一个字符{c-='a';S[++n] = c;int cur = get_fail(last); //通过上一个回文串找这个串的匹配位置if(!nxt[cur][c]){//这个回文串从未出现过int now = newnode(len[cur] + 2);fail[now] = nxt[get_fail(fail[cur])][c]; //和AC自动机简直不要太类似nxt[cur][c] = now;num[now] = num[fail[now]] + 1;}last = nxt[cur][c];++cnt[last];id[last] = n;//}inline void count1()//计数{for(int i = p - 1; i >= 0; --i) cnt[fail[i]]+= cnt[i];for (int i = 2; i < p; i++){///cout << id[i] - len[i] << " " << id[i] - 1 << endl;if (check(id[i] - len[i], id[i] - 1)){ret[len[i]] += cnt[i];}}}inline void work(){pp[0] = 1;for (int i = 1; i < N; i++){pp[i] = hash1 * pp[i - 1];}memset(ret, 0, sizeof(ret));init();int slen = strlen(str);ha[0] = str[0];for (int i = 0; i < slen; i++){add(str[i]);}for (int i = 1; i < slen; i++){ha[i] = ha[i - 1] * hash1 + str[i];}count1();printf("%lld", ret[1]);for (int i = 2; i <= slen; i++){printf(" %lld", ret[i]);}printf("\n");}} pam ;
int main()
{while(~ss(str))pam.work();return 0;
}

2019暑期杭电多校HDU6599 I Love Palindrome String相关推荐

  1. 2019年杭电多校第一场 1001题blank(DP)HDU6578

    2019年杭电多校第一场 1001题blank(DP)HDU6578 解决思路,开一个DP数组来存储0 1 2 3四个字符最后出现的位置,并且在DP中已经==排好序==. DP开四维,DP[i][j] ...

  2. HDU-6578 Blank(DP)2019暑假杭电多校第一场

    题意:一行有n个空格编号1~n; 每一个空格中填入0,1,2,3中的一个数字.且满足m个限制l,r,x:满足在区间[l,r]正好有x种不同的数字. 有多少种方法可以填充空格以满足所有条件? 思路:dp ...

  3. 2019暑假杭电多校第6场签到题-1008-TDL

    题目传送门 思路: 估计出n的范围,暴力就完事. 异或就是不进位的加法 (f(n,m) - n)^n == k, f(n,m)-n==k^n; 因为灯饰右边估计不会超过1e3,所以k^n<=1e ...

  4. 2019杭电多校 第七场 Kejin Player 6656(求期望值)

    2019杭电多校 第七场 Kejin Player 6656(求期望值) 题目 http://acm.hdu.edu.cn/showproblem.php?pid=6656 题意 给你n,q.表示有n ...

  5. HDU-6599 I Love Palindrome String 杭电第二次多校赛(Manacher+回文自动机)

    HDU-6599 I Love Palindrome String 杭电第二次多校赛(Manacher+回文自动机) 我的博客:https://acmerszq.cn 原题链接:http://acm. ...

  6. 【2019杭电多校训练赛】HDU6681 / 1002-Rikka with Cake 题解(扫描线)

    [2019杭电多校训练赛]HDU6681 / 1002-Rikka with Cake 题解 题意 思路 代码 题目来自于:HDU6681 Rikka with Cake 题意 题目的大意是给定你一个 ...

  7. 2019杭电多校第9场1002 Rikka with Cake HDU6681

    2019杭电多校第9场1002 Rikka with Cake HDU6681 题意:给你若干个点按上下左右切割平面,最后问平面内有几块被切割开来. 解法1:红黑树+思维+贪心 A:根据欧拉定理可以得 ...

  8. 2019.7.29 杭电多校第三场小结

    index > 杭电多校第三场 题号 标题 AC 做法 状态 6603 Azshara's deep sea (51/150)34.00% 6604 Blow up the city (213/ ...

  9. 浙江杭电计算机系的秦嘉珩,迎新季丨@2019级杭电小萌新,你们的最美辅导员上线啦!...

    原标题:迎新季丨@2019级杭电小萌新,你们的最美辅导员上线啦! 2019级小萌新们 欢迎大家加入杭州电子科技大学 在即将开启的四年大学生活中 有这样一位亲切的老师 陪你军训,与你谈心,为你保驾护航 ...

最新文章

  1. Mybatis操作主体流程
  2. 华为UPS“内外”兼修
  3. “sudo: go:找不到命令”完美解决方案
  4. python容器数据类型_python collections 容器数据类型
  5. 深入grootJs(进阶教程)
  6. spd耗材管理流程图_国药器械山东公司助力济宁医学院附属医院SPD项目成功启动...
  7. 杨波 微服务技术专家_专家称,这些是最有效的微服务测试策略
  8. 高级数据库,建库,建表,建约束
  9. [Java] 读写字符串数据
  10. google 插件_Google浏览器常用插件与使用小技巧
  11. 252个核心词根——词缀(前缀-后缀)总结大全【最全-一文看懂!!!】
  12. cosx sinx 泰勒展开 C++
  13. python层次分析法案例_在R语言中使用层次分析法-案例1
  14. 【无标题】安装 Debian 11 Bullseye – 一步一步的截图
  15. c语言怎么让程序停止3秒,c语言暂停语句1秒
  16. 大聊Python----Select解析
  17. 微服务--应对每秒上万并发下的参数优化实战(实战经验)
  18. Wormhole连接教程
  19. 主数据标准化项目阶段划分、实施难点及应对措施经验分享
  20. matlab单位采样序列程序,常用序列的MATLAB代码(一)

热门文章

  1. Android11不申请储存权限,Dolphin 模拟器开发者:由于 Android 11 存储权限收紧,模拟器功能将受限...
  2. ROS在MATLAB中的使用笔记
  3. Android应用源码商城商品交易客户端小框架源码下载
  4. 13 罗马数字转整数
  5. 计算机积极拒绝访问 夜神模拟器,夜神模拟器127.0.0.1:62001: 由于目标 计算机积极拒绝,无法连接 解决方法...
  6. 0.96寸OLED取字模文字显示
  7. 2019.4.8 1532 Drainage Ditches
  8. Arduino-CCS-811检测空气中CO2和VOC含量(超详细)
  9. 源码 | Arduino + EMQ X + Spring Boot + Vue 开源全栈物联网智能家居系统
  10. 【一文看懂】深度神经网络加速和压缩新进展年度报告