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 ...
随机推荐
- c++中为什么可以通过指针或引用实现多态,而不可以通过对象呢?
引言: 在c++中司空见惯的事情就是:可以通过指针和引用可以实现多态,而对象不可以. 那为什么?让我们来解开这神秘的暗纱! 1. 类对象的存储方式: 在一个类的实例中,只会存放非静态的成员变量. ...
- unix下ksh获取昨天的日期
http://blog.chinaunix.net/uid-27795718-id-3347473.html 总结:使用了TZ以后,时间立刻变伦敦时间.如果你打算用"TZ=aaa24 dat ...
- Java不区分大小写的CaseInsensitiveMap
Java中对于键值对,我们习惯使用类HashMap,使用方式:Map<String, String> result=new HashMap<String,String>(); ...
- C#WinForm窗体内Panel容器中嵌入子窗体、程序主窗体设计例子
C#WinForm父级窗体内Panel容器中嵌入子窗体.程序主窗体设计例子 在项目开发中经常遇到父级窗体嵌入子窗体所以写了一个例子程序,顺便大概划分了下界面模块和配色,不足之处还望指点 主窗体窗体采用 ...
- 前端上传 base64 编码图片到七牛云存储
参考文档 如何上传base64编码图片到七牛云 调试过程 文档中分别有 java 和 html 的 demo,可以根据文档示例调试. 下面是我调试的过程,可以作为参考,特别注意的是,如果需要给文件起名 ...
- jqeury点击空白关闭弹窗
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- js获取谷歌浏览器版本 和 js分辨不同浏览器
// 获取谷歌版本 function getChromeVersion() { var arr = navigator.userAgent.split(' '); var chromeVersion ...
- 对Http协议基本原理的理解
超文本传输协议 超文本传输协议(HTTP,HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络传输协议,所有的WWW文件都必须遵守这个标准.设计HTTP最初的目的是 ...
- Oracle课程档案,第三天
count(*):有多少行,对行做统计 count(x):列.... sum:和 avg:平均值 min:求最小值 max:求最大值 distinct:取出重复的值 count:计数 group by ...
- Java应用之shiro
Apache Shiro是一个强大而灵活的开源安全框架,它能够干净利落地处理身份认证,授权,企业会话管理和加密. 以下是你可以用 Apache Shiro所做的事情: 1.验证用户 2. 对用户执行访 ...