Interesting (manacher + 前缀和处理)
题意:相邻的两端回文串的价值为两个回文串总的区间左端点 × 区间右端点。然后计算目标串中所有该情况的总和。
思路:首先用manacher求出所有中心点的最大半径,然后我们知道对于左区间我们把贡献记录在右端点,右区间记录在左端点。然后细节的我就不太懂了。迷~
#include<bits/stdc++.h>
using namespace std; const int maxn = 2e6 +;
const int mod = 1e9 + ;
long long rad[maxn], L[maxn], R[maxn], cnt1[maxn], cnt2[maxn];
char in[maxn], str[maxn]; void manacher(){
int len = strlen(in), l = ;
str[l ++] = '$'; str[l ++] = '#';
for(int i = ; i < len; i ++)
str[l ++] = in[i], str[l ++] = '#';
str[l] = ;
int mx = , id = ;
for(int i = ; i < l; i ++) {
rad[i] = mx > i ? min(rad[ * id - i], 1LL * mx - i) : ;
while(str[i + rad[i]] == str[i - rad[i]]) rad[i] ++;
if(i + rad[i] > mx){
mx = i + rad[i];
id = i;
}
}
} int main(){ while(~scanf("%s", in)) {
int len = strlen(in);
manacher();
// for(int i = 0; i < 2 * len + 2; i ++) printf(" %d ", rad[i]);
memset(cnt1, , sizeof(cnt1));
memset(cnt2, , sizeof(cnt2));
for(int i = ; i <= * len; i ++){
cnt1[i - rad[i] + ] += i; cnt1[i + ] -= i;
cnt2[i - rad[i] + ] ++; cnt2[i + ] --;
}
for(int i = ; i <= * len; i ++){
cnt1[i] += cnt1[i - ], cnt2[i] += cnt2[i - ];
if(i % == ) R[i/] = (cnt1[i] - i / * cnt2[i]) % mod;
}
memset(cnt1, , sizeof(cnt1));
memset(cnt2, , sizeof(cnt2));
for(int i = ; i <= * len; i ++) {
cnt1[i + rad[i]] -= i; cnt1[i] += i;
cnt2[i + rad[i]] --; cnt2[i] ++;
}
for(int i = ; i <= * len; i ++) {
cnt1[i] += cnt1[i - ]; cnt2[i] += cnt2[i - ];
if(i % == ) L[i / ] = (cnt1[i] - i / * cnt2[i]) % mod;
}
long long ans = ;
for(int i = ; i < len; i ++) ans = (ans + L[i] * R[i + ] % mod) % mod;
printf("%lld\n", ans);
}
return ;
}
Interesting (manacher + 前缀和处理)的更多相关文章
- 多校1005 HDU5785 Interesting (manacher)
// 多校1005 HDU5785 Interesting // 题意:给你一个串,求相邻两个回文串左边端点*右边端点的和 // 思路:马拉车算出最长回文半径,求一个前缀和,既得到每个点对答案的贡献. ...
- 【HDU5785】Interesting [Manacher]
Interesting Time Limit: 30 Sec Memory Limit: 256 MB[Submit][Status][Discuss] Description Input Outp ...
- HDU-3613-Best Reward(Manacher, 前缀和)
链接: https://vjudge.net/problem/HDU-3613 题意: After an uphill battle, General Li won a great victory. ...
- HDU 5785 Interesting manacher + 延迟标记
题意:给你一个串,若里面有两个相邻的没有交集的回文串的话,设为S[i...j] 和 S[j+1...k],对答案的贡献是i*k,就是左端点的值乘上右端点的值. 首先,如果s[x1....j].s[x2 ...
- cf519D. A and B and Interesting Substrings(前缀和)
题意 给出$26$个字母对应的权值和一个字符串 问满足以下条件的子串有多少 首尾字母相同 中间字母权值相加为0 Sol 我们要找到区间满足$sum[i] - sum[j] = 0$ $sum[i] = ...
- 【SAM manacher 倍增】bzoj3676: [Apio2014]回文串
做法一:PAM:做法二:SAM+manacher.前缀树上倍增 Description 考虑一个只包含小写拉丁字母的字符串s.我们定义s的一个子串t的“出 现值”为t在s中的出现次数乘以t的长度.请你 ...
- Gym - 101981M The 2018 ICPC Asia Nanjing Regional Contest M.Mediocre String Problem Manacher+扩增KMP
题面 题意:给你2个串(长度1e6),在第一个串里找“s1s2s3”,第二个串里找“s4”,拼接后,是一个回文串,求方案数 题解:知道s1和s4回文,s2和s3回文,所以我们枚举s1的右端点,s1的长 ...
- HDU5785 Interesting(Manacher + 延迟标记)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5785 Description Alice get a string S. She think ...
- hdu3613 Best Reward manacher+贪心+前缀和
After an uphill battle, General Li won a great victory. Now the head of state decide to reward him w ...
随机推荐
- 抖音圈圈乐 系统搭建H5微信小游戏圈圈乐系统介绍
网红线下游戏抖音圈圈乐改造而来 一.搭建此系统需要准备如下资料: 1. 认证微信服务号 2. 微信支付商户号 3. 备案域名及云服务器 二.系统功能简介: 1. 游戏闯关 2. 每个商品闯关难度后台自 ...
- 转 .NET4.5之初识async与await
来自:http://www.cnblogs.com/lekko/archive/2013/03/05/2944282.html 本人是从.NET4.0刚出的时候接触的.NET环境,所以学的东西就是4. ...
- MySQL加密解密
1. 加密:mysql323,不可逆 select old_password('bbs.antian365.com'); # 10c886615b135b38 2. 加密:mysqlsha1,不可逆 ...
- c++ 模板相关
https://blog.csdn.net/lezardfu/article/details/60466161 https://www.cnblogs.com/ymy124/p/3632634.htm ...
- ES6 export
一.默认导出(default export)// 1.一个模块只能有一个默认导出, 对于默认导出, 导入的名称可以和导出的名称不一致, 这对于导出匿名函数或类非常有用. <!---- page. ...
- Github Upload Large File 上传超大文件
Github中单个文件的大小限制是100MB,为了能突破这个限制,我们需要使用Git Large File Storage这个工具,参见这个官方帖子,但是按照其给的步骤,博主未能成功上传超大文件,那么 ...
- UCloud 机房的网络搭建(计蒜客初赛第五场)
UCloud 刚刚建立一个新机房,近日正在进行网络搭建.机房内有 nn 台服务器和 mm 个分线器,整个机房只有一个网线出口.分线器的作用是将一根网线转换成多根网线.蒜头君也知道每个分线器输出的最大网 ...
- juqery 点击张三触发李四的方法 trigger(); 和 被选元素前插入指定的内容的方法 brfore();
$('.zc_fabu_img_1').on('click',function(){ $("#upImg img").trigger("click"); }) ...
- PHP(css样式)
布局页面的时候 大色块 小色块 ...(就是宽高) 内容布局:浮动,定位,显示,层级 浮动:float(样式名):值:left right设一个父标签,设定宽高,里面随便浮动!!!!!!!!!!!!! ...
- Java编程基础篇第四章
循环结构 循环结构的分类 for循环,while循环,do...while()循环 for循环 注意事项: a:判断条件语句无论简单还是复杂结果是boolean类型 b:循环体语句如果是一条语句,大括 ...