题面

题意:给你一个字符串,问你满足s[i]=s[2n-i]=s[2n+i-2]的子串(这子串长度为3n-2)有多少个,原字符串长度<=5e5

题解:对于这种子串,其实要满足2个回文,跑过一次Manacher后,len[i]表示以i向两边扩展最远的回文串长度,

那么对于答案,实际就是统计满足下列条件(i,j)的对数

i  <= j

j - i <= len[i]

j - i <= len[j]

移项就是

i >= j -  len[j]

j <= i + len[i]

那么相当于,枚举i,询问(i,i+len[i])区间内,有多少个数(这里指权值 j - len[j])小于等于i

就是问区间内小于某个数的个数,那就是主席树裸题(好像其他人都写的树状树状ORZ)

  1. #include<bits/stdc++.h>
  2. #define N 500505
  3. using namespace std;
  4. int sum[N*],rt[N*],lc[N*],rc[N*];
  5. int a[N],b[N],len[N],p,node_cnt,cnt,value[N];
  6. char s[N];
  7. void build(int &t,int l, int r)
  8. {
  9. t=++node_cnt;
  10. sum[t]=;
  11. if (l==r) return;
  12. int mid=(l+r)>>;
  13. build(lc[t],l,mid);
  14. build(rc[t],mid+,r);
  15. }
  16. int modify(int o,int l,int r)
  17. {
  18. int oo = ++node_cnt;
  19. lc[oo]=lc[o]; rc[oo]=rc[o]; sum[oo]=sum[o]+;
  20. if (l==r) return oo;
  21. int mid=(l+r)>>;
  22. if (p<=mid) lc[oo]=modify(lc[oo],l,mid);
  23. else rc[oo]=modify(rc[oo],mid+,r);
  24. return oo;
  25. }
  26. int query(int u,int v,int l,int r,int k)
  27. {
  28. int ans,mid=((l+r)>>);
  29. if (r<=k) return sum[v]-sum[u];
  30. if (l>k) return ;
  31. ans=query(lc[u],lc[v],l,mid,k);
  32. if (mid<k) ans=ans+query(rc[u],rc[v],mid+,r,k);
  33. return ans;
  34. }
  35. void manacher()
  36. {
  37. int pos=,R=;
  38. for (int i=;i<=cnt;i++)
  39. {
  40. if (i<R) len[i]=min(len[*pos-i],R-i); else len[i]=;
  41. while (<=i-len[i]&&i+len[i]<=cnt&&s[i-len[i]]==s[i+len[i]]) len[i]++;
  42. if (i+len[i]>R) {pos=i;R=i+len[i];}
  43. }
  44. for(int i=;i<=cnt;i++)
  45. {
  46. a[i]=i-len[i]+;
  47. b[i]=a[i];
  48. }
  49. }
  50. int main()
  51. {
  52. int k, n, q, nn, v, l, r, x,T;
  53. scanf("%d\n",&T);
  54. while (T--)
  55. {
  56. scanf("%s",s+);
  57. cnt=strlen(s+);
  58. manacher();
  59. sort(b+,b++cnt);
  60. nn=unique(b+,b+cnt+)-b-;
  61. node_cnt=;
  62. build(rt[],,nn);
  63. for (int i=;i<=cnt;i++)
  64. {
  65. p=lower_bound(b+,b+nn+,a[i])-b;
  66. rt[i]=modify(rt[i-],,nn);
  67. }
  68. long long ans=;
  69. for (int i=;i<=cnt;i++)
  70. {
  71. x=lower_bound(b+,b+nn+,i)-b;
  72. if (x==nn+) x--;
  73. if (b[x]>i) x--;
  74. if(x==) continue;
  75. if(min(len[i]+i-,cnt)<i+) continue;
  76. ans=ans+query(rt[i],rt[min(len[i]+i-,cnt)],,nn,x);
  77. }
  78. printf("%lld\n",ans);
  79. }
  80. }

Hdu-6230 2017CCPC-哈尔滨站 A.Palindrome Manacher 主席树的更多相关文章

  1. HDU 4729 An Easy Problem for Elfness (主席树,树上第K大)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 题意:给出一个带边权的图.对于每一个询问(S , ...

  2. HDU - 6231 K-th Number (2017CCPC哈尔滨站 二分+尺取法)

    Alice are given an array A[1..N] with N numbers. Now Alice want to build an array B by a parameter K ...

  3. 2017中国大学生程序设计竞赛-哈尔滨站 A - Palindrome

    Palindrome Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Tota ...

  4. HDU 4729 An Easy Problem for Elfness(主席树)(2013 ACM/ICPC Asia Regional Chengdu Online)

    Problem Description Pfctgeorge is totally a tall rich and handsome guy. He plans to build a huge wat ...

  5. 2019CCPC网络赛 C - K-th occurrence HDU - 6704(后缀数组+ST表+二分+主席树)

    题意 求区间l,r的子串在原串中第k次出现的位置. 链接:https://vjudge.net/contest/322094#problem/C 思路 比赛的时候用后缀自动机写的,TLE到比赛结束. ...

  6. 杭电多校HDU 6601 Keen On Everything But Triangle(主席树)题解

    题意: 有\(n\)根长度不一的棍子,q次询问,求\([L,R]\)区间的棍子所能组成的周长最长的三角形.棍长\(\in [1, 1e9]\),n\(\in [1, 1e5]\). 思路: 由于不构成 ...

  7. HDU 6230

    Palindrome Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Tota ...

  8. 2017 ccpc哈尔滨 A题 Palindrome

    2017 ccpc哈尔滨 A题 Palindrome 题意: 给一个串\(T\),计算存在多少子串S满足\(S[i]=S[2n−i]=S[2n+i−2](1≤i≤n)\) 思路: 很明显这里的回文串长 ...

  9. HDU 4417 Super Mario(主席树求区间内的区间查询+离散化)

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

随机推荐

  1. Deutsch lernen (02)

    1. fließend a. 流利的 Meine französische Freundin spricht fließend Deutsch.     流动的 Der Verkehr wickelt ...

  2. WebForm 登陆test

    <script> window.onload = function () { document.getElementById("form1").onsubmit = f ...

  3. Memcached 之分布式算法原理

    memcached并不像mongodb一样可以配置多个节点,并且节点之间可以”自动分配数据“,即相互通信,所以我们在做memcache分布式集群的时候要有一个算法来保证当一台memcache服务器宕机 ...

  4. esp32使iOS 获取蓝牙外设的Mac地址

    最近在做一个需要上下位机的项目,我负责的任务下位机,使用的主控芯片是esp32.这个项目中有一项是需要手机扫描二维码然后连接作为esp32的蓝牙.二维码中包含了mac地址信息,在手机扫描周围设备的时候 ...

  5. [Usaco2004 Open]Cube Stacking 方块游戏

    题面:     约翰和贝茜在玩一个方块游戏.编号为1到n的n(1≤n≤30000)个方块正放在地上.每个构成一个立方柱.    游戏开始后,约翰会给贝茜发出P(1≤P≤100000)个指令.指令有两种 ...

  6. Solr数据不同步

    Solr配置了集群,本地有253和254,2个独立的Solr服务.  同一个页面的图片,刷新2次,图片地址不一样,最后查明,后台数据源Solr1和Solr2的数据不一致.    第1步推测:本地缓存, ...

  7. Porting from Oracle to MySQL

    A potential customer asked my about porting her application from Oracle Database to MySQL. I always ...

  8. HDU4572 Bottles Arrangement

    /* HDU4572 Bottles Arrangement http://acm.hdu.edu.cn/showproblem.php?pid=4572 数论 找规律 题意:有m行n列和1-n的数各 ...

  9. nutz_web应用中主页跳转到登录页面的方式

    一.前言 web应用开发时,地址栏输入ip+port+appName,通常可以跳转到登录页面.以下便介绍我所知道并且验证过的三种跳转方式. 二.准备工作 需要使用到两个url的处理分别如下: @At( ...

  10. 如何实现网卡bond

    https://jingyan.baidu.com/article/375c8e19da666325f2a229f7.html