题目传送门

  需要高级权限的传送门

题目大意

  对于一个01字符串,如果将这个字符串0和1取反后,再将整个串反过来和原串一样,就称作“反对称”字符串。

  问给定长度为$n$的一个01串有多少个子串是反对称的。

  这个反对称子串满足回文串的对称性质,和"子结构"性质(例如$s$的$[a, b]\ (a + 2 < b)$一段是反对称的,那么$s$的$[a + 1, b - 1]$也是反对称的)

  因此我们可以用Manacher来搞这个问题。只是改一下判断的条件罢了。

  当然还有Hash + 二分的做法。

  枚举对称中心,然而二分对称长度。

  jmr同学有一个很神奇的想法,把1变成01,0变成10,然后跑Manacher,算答案的时候处理一下。

Code

 /**
* bzoj
* Problem#2084
* Accepted
* Time: 116ms
* Memory: 3728k
*/
#include <bits/stdc++.h>
#ifndef WIN32
#define Auto "%lld"
#else
#define Auto "%I64d"
#endif
using namespace std;
typedef bool boolean; const int N = 5e5 + ; int n;
int ps[N];
char str[N]; inline void init() {
scanf("%d", &n);
scanf("%s", str + );
} long long res = ;
inline void solve() {
int p = , mx = ;
for (int i = , l, r; i <= n; i++) {
if (i > mx) {
l = i - , r = i;
while (l > && r <= n && str[l] != str[r]) l--, r++, ps[i]++;
} else {
ps[i] = min(mx - i + , ps[p * - i]);
while (i - ps[i] > && i + ps[i] <= n && str[i + ps[i]] != str[i - - ps[i]]) ps[i]++;
}
if (i + ps[i] - > mx)
mx = i + ps[i] - , p = i;
res += ps[i];
/// cerr << i << " " << ps[i] << endl;
}
printf(Auto"\n", res);
} int main() {
init();
solve();
return ;
}

bzoj 2084 Antisymmetry - Manacher的更多相关文章

  1. bzoj 2084: Antisymmetry 回文自动机

    题目: Description 对于一个01字符串,如果将这个字符串0和1取反后,再将整个串反过来和原串一样,就称作"反对称"字符串.比如00001111和010101就是反对称的 ...

  2. BZOJ 2084: [Poi2010]Antisymmetry [Manacher]

    2084: [Poi2010]Antisymmetry Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 609  Solved: 387[Submit] ...

  3. BZOJ 2084 [Poi2010]Antisymmetry(manacher)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2084 [题目大意] 对于一个01字符串,如果将这个字符串0和1取反后, 再将整个串反过 ...

  4. BZOJ 2084: [Poi2010]Antisymmetry

    Sol Manacher. \(O(n)\) Manacher很简单啊.改一改转移就可以了. 然后我WA了.一开始天真的认为id只会是奇数,然后就GG. 一组 Hack 数据 3 1 0 0 然后就跳 ...

  5. bzoj 2084: [Poi2010]Antisymmetry【回文自动机】

    manacher魔改,hash+二分都好写,但是我魔改了个回文自动机就写自闭了orz 根本上来说只要把==改成!=即可,但是这样一来很多停止条件就没了,需要很多特判手动刹车,最后统计一下size即可 ...

  6. BZOJ 2084 二分+hash OR Manacher

    思路: 二分+哈希 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> ...

  7. bzoj 2084

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2084 这道题很容易想到就是一个变种的最长回文字串, 不过回文的规则变成了s[i + p[i] ...

  8. bzoj 3325 密码 - Manacher

    题目传送门 需要root权限的传送点 题目大意 已知一个串,以每个字符为中心的最长回文串长,以及每两个字符中间为中心的最长回文串长.求字典序最小的这样一个串.题目保证有解. 考虑Manacher的过程 ...

  9. BZOJ 3160 FFT+Manacher

    思路: 这道题思路好奇怪--. 我们先要知道关于x (x可以是间隙) 对称的有几对字母 显然暴力是n^2的 那怎么办呢 先把所有'a'看成1 'b'看成0 意外的发现 这不就是卷积嘛 再倒过来搞一搞 ...

随机推荐

  1. 利用css伪类编写冒泡小三角

    HTML代码 <div class="lf otherLogin"> <span>其他方式注册</span> <div class=&qu ...

  2. vue中点击复制粘贴功能

    1.下载clipboard.js cnpm install clipboard --save 2.引入,可以在mian.js中全局引入也可以在单个vue中引入 import Clipboard fro ...

  3. 输出调试技巧 PRINTF()

    #define PRINTF(...) \ do { \ printf( "%d:%s::",__LINE__, __FUNCTION__);\ printf(__VA_ARGS_ ...

  4. ubuntu python 安装numpy,scipy.pandas.....

    http://blog.csdn.net/Yakumoyukarilan/article/details/51340358

  5. python将目录切换为脚本所在目录

    os.chdir(os.path.abspath(os.path.dirname(sys.argv[0])))

  6. CSS小知识-----前缀-moz-、-ms-、-webkit-,-o-分别代表的意思

    这种方式在业界上统称:识别码.前缀 -ms-代表[ie]内核识别码 -moz-代表火狐[firefox]内核识别码 -webkit-代表谷歌[chrome]/苹果[safari]内核识别码 -o-代表 ...

  7. django之视图view小知识

    CBV简版流程 AddPublisher.as_view() ——> view 函数 当请求来的时候才执行view view中执行: 1. 先实例化AddPublisher,给self def ...

  8. c# Applicatcontext类

    Application类(位于System.Windows.Forms命名空间)公开了Run方法,可以调用该方法来调度应用程序进入消息循环.Run方法有三个重载 1.第一个重载版本不带任何参数,比较少 ...

  9. There is no session with id XXX

    系统采用 shiro + redis + spring来做的权限控制系统.   登录时报 there is no session with XXX 跟踪断点发现,系统查询session时,查不到red ...

  10. Codeforce 791A - Bear and Big Brother

    Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. ...