传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2084

这道题很容易想到就是一个变种的最长回文字串, 不过回文的规则变成了s[i + p[i]] + s[i - p[i]] == 1 可以用hash 来nlogn, 不过最优是用manacher, 然后有一个非常迷的查空位的方法(' '       ) 可以看代码

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std; const int maxn = 20000100;
int n; long long ans = 0;
char s[maxn];
int st[maxn]; void read() {
scanf("%d", &n);
scanf("%s", s + 1);
for(int i = 1; i <= n; ++ i) st[i << 1] = (s[i] == '0' ? 0 : 2);
n <<= 1; ++ n;
for(int i = 1; i <= n; i += 2) st[i] = 1;
} int p[maxn]; void sov() {
int mx, id; mx = 0, id = 0;
for(int i = 1; i <= n; i += 2) {
if(mx > i) p[i] = min(p[2 * id - i], mx - i);
else p[i] = 1;
for(; i - p[i] > 0 && i + p[i] <= n && st[i - p[i]] + st[i + p[i]] == 2; ++ p[i]);
if(i + p[i] > mx) mx = i + p[i], id = i;
}
for(int i = 1; i <= n; i += 2) ans += (long long)((p[i] - 1) >> 1);
printf("%lld\n", ans);
} int main() {
//freopen("test.in", "r", stdin);
read(), sov();
return 0;
}

bzoj 2084的更多相关文章

  1. bzoj 2084 Antisymmetry - Manacher

    题目传送门 需要高级权限的传送门 题目大意 对于一个01字符串,如果将这个字符串0和1取反后,再将整个串反过来和原串一样,就称作“反对称”字符串. 问给定长度为$n$的一个01串有多少个子串是反对称的 ...

  2. BZOJ 2084: [Poi2010]Antisymmetry

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

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

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

  4. BZOJ 2084 [Poi2010]Antisymmetry(manacher)

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

  5. bzoj 2084: Antisymmetry 回文自动机

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

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

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

  7. BZOJ 2084 二分+hash OR Manacher

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

  8. 【BZOJ】【2084】【POI2010】Antisymmetry

    Manacher算法 啊……Manacher修改一下就好啦~蛮水的…… Manacher原本是找首尾相同的子串,即回文串,我们这里是要找对应位置不同的“反回文串”(反对称?233) 长度为奇数的肯定不 ...

  9. [原博客] POI系列(4)

    正规.严谨.精妙. -POI BZOJ 1531 : [POI2005]Bank notes 裸的背包,可以二进制拆分一下.一个物品比如说有n个,可以拆成 1,2,4,8,16...个. OJ上没有样 ...

随机推荐

  1. 集成swagger

    1.看官方文档 https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/getting-started-with-swashbuckle?view ...

  2. sql-主键、外键、索引

    SQL的主键和外键的作用: 外键取值规则:空值或参照的主键值. (1)插入非空值时,如果主键表中没有这个值,则不能插入. (2)更新时,不能改为主键表中没有的值. (3)删除主键表记录时,你可以在建外 ...

  3. win7 SP1 64位 原版 百度网盘下载

    下载地址:https://pan.baidu.com/s/1bnOtKU5YH4gSr1RmZR2BkQ 提取码 :s9o7 扫码下载:

  4. css使子元素在父元素居中的各种方法

    html结构: <div class="parent"> <div class="child"></div> </di ...

  5. Cent OS 7下安装 mongodb

    1.下载MongoDB 安装包 wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.8.tgz 2.解压并安装 .tgz 3. ...

  6. ASP.NET Error Handling

    https://docs.microsoft.com/en-us/aspnet/web-forms/overview/getting-started/getting-started-with-aspn ...

  7. 如何理解 HTML 语义化?

    先看下面两段代码 <div>标题</div> <div> <div>一段文字</div> <div> <div>列表 ...

  8. cs224d 作业 problem set2 (一) 用tensorflow纯手写实现sofmax 函数,线性判别分析,命名实体识别

    Hi Dear Today we will use tensorflow to implement the softmax regression and linear classifier algor ...

  9. 4、jQuery面向对象之简单的插件开发

    1.alert例子 (function($){ $.alert = function(msg){ window.alert(msg); } $.fn.alert = function(msg){ wi ...

  10. 分析/proc/[pid]/maps中的各个内存区域的大小

    cat maps | sed -e "s/\([0-9a-f]\{8\}\)-\([0-9a-f]\{8\}\)/0x\1 0x\2/" | awk '{printf(" ...