题意:相邻的两端回文串的价值为两个回文串总的区间左端点 × 区间右端点。然后计算目标串中所有该情况的总和。

  思路:首先用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 + 前缀和处理)的更多相关文章

  1. 多校1005 HDU5785 Interesting (manacher)

    // 多校1005 HDU5785 Interesting // 题意:给你一个串,求相邻两个回文串左边端点*右边端点的和 // 思路:马拉车算出最长回文半径,求一个前缀和,既得到每个点对答案的贡献. ...

  2. 【HDU5785】Interesting [Manacher]

    Interesting Time Limit: 30 Sec  Memory Limit: 256 MB[Submit][Status][Discuss] Description Input Outp ...

  3. HDU-3613-Best Reward(Manacher, 前缀和)

    链接: https://vjudge.net/problem/HDU-3613 题意: After an uphill battle, General Li won a great victory. ...

  4. HDU 5785 Interesting manacher + 延迟标记

    题意:给你一个串,若里面有两个相邻的没有交集的回文串的话,设为S[i...j] 和 S[j+1...k],对答案的贡献是i*k,就是左端点的值乘上右端点的值. 首先,如果s[x1....j].s[x2 ...

  5. cf519D. A and B and Interesting Substrings(前缀和)

    题意 给出$26$个字母对应的权值和一个字符串 问满足以下条件的子串有多少 首尾字母相同 中间字母权值相加为0 Sol 我们要找到区间满足$sum[i] - sum[j] = 0$ $sum[i] = ...

  6. 【SAM manacher 倍增】bzoj3676: [Apio2014]回文串

    做法一:PAM:做法二:SAM+manacher.前缀树上倍增 Description 考虑一个只包含小写拉丁字母的字符串s.我们定义s的一个子串t的“出 现值”为t在s中的出现次数乘以t的长度.请你 ...

  7. 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的长 ...

  8. HDU5785 Interesting(Manacher + 延迟标记)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5785 Description Alice get a string S. She think ...

  9. hdu3613 Best Reward manacher+贪心+前缀和

    After an uphill battle, General Li won a great victory. Now the head of state decide to reward him w ...

随机推荐

  1. 理解和解决Java并发修改异常ConcurrentModificationException(转载)

    原文地址:https://www.jianshu.com/p/f3f6b12330c1 理解和解决Java并发修改异常ConcurrentModificationException 不知读者在Java ...

  2. 115、如何构建Android MVVM 应用框架(转载)

    转载:http://android.jobbole.com/85198/

  3. Ionic异常及解决

    1. 编译时提示: ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:fontV ...

  4. 命令行部署SharePoint2016离线前提条件和添加服务器的Feature

    前言 Sp2016的软件环境要求如下: 服务器场中的数据库服务器的最低要求: 以下各项之一: Microsoft SQL Server 2014 Service Pack 1 (SP1) 的 64 位 ...

  5. 第六天 py 加法练习

    其实就是while的用法!   该看第65 啦

  6. redis(四)--简单实现Redis缓存中的排序功能

    在实现缓存排序功能之前,必须先明白这一功能的合理性.不妨思考一下,既然可以在数据库中排序,为什么还要把排序功能放在缓存中实现呢?这里简单总结了两个原因:首先,排序会增加数据库的负载,难以支撑高并发的应 ...

  7. 1. node.js 认识 (一)

    官网: (下载安装nodejs) https://nodejs.org/en/ http://nodejs.cn/ Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环 ...

  8. jquery的设计亮点

    jquery的亮点我目前学习到一下几点: 1.封装库利用window的挂载实现闭包. 库一定要封装来防止变量污染全局,方式要么对象,要么立即执行函数.jquery用了立即执行函数.因为立即执行函数里的 ...

  9. oracle的高级查询

    1.简单连接 基本连接语法:SELECT [ALL|DISTINCT]column_name[,expression…]FROM table1_name[,table2_name,view_name, ...

  10. C#遍历枚举(Enum)值

    foreach (object o in Enum.GetValues(typeof(EmpType))) { Console.WriteLine("{0}:{1}", o, En ...