Hdu-6230 2017CCPC-哈尔滨站 A.Palindrome Manacher 主席树
题意:给你一个字符串,问你满足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)
- #include<bits/stdc++.h>
- #define N 500505
- using namespace std;
- int sum[N*],rt[N*],lc[N*],rc[N*];
- int a[N],b[N],len[N],p,node_cnt,cnt,value[N];
- char s[N];
- void build(int &t,int l, int r)
- {
- t=++node_cnt;
- sum[t]=;
- if (l==r) return;
- int mid=(l+r)>>;
- build(lc[t],l,mid);
- build(rc[t],mid+,r);
- }
- int modify(int o,int l,int r)
- {
- int oo = ++node_cnt;
- lc[oo]=lc[o]; rc[oo]=rc[o]; sum[oo]=sum[o]+;
- if (l==r) return oo;
- int mid=(l+r)>>;
- if (p<=mid) lc[oo]=modify(lc[oo],l,mid);
- else rc[oo]=modify(rc[oo],mid+,r);
- return oo;
- }
- int query(int u,int v,int l,int r,int k)
- {
- int ans,mid=((l+r)>>);
- if (r<=k) return sum[v]-sum[u];
- if (l>k) return ;
- ans=query(lc[u],lc[v],l,mid,k);
- if (mid<k) ans=ans+query(rc[u],rc[v],mid+,r,k);
- return ans;
- }
- void manacher()
- {
- int pos=,R=;
- for (int i=;i<=cnt;i++)
- {
- if (i<R) len[i]=min(len[*pos-i],R-i); else len[i]=;
- while (<=i-len[i]&&i+len[i]<=cnt&&s[i-len[i]]==s[i+len[i]]) len[i]++;
- if (i+len[i]>R) {pos=i;R=i+len[i];}
- }
- for(int i=;i<=cnt;i++)
- {
- a[i]=i-len[i]+;
- b[i]=a[i];
- }
- }
- int main()
- {
- int k, n, q, nn, v, l, r, x,T;
- scanf("%d\n",&T);
- while (T--)
- {
- scanf("%s",s+);
- cnt=strlen(s+);
- manacher();
- sort(b+,b++cnt);
- nn=unique(b+,b+cnt+)-b-;
- node_cnt=;
- build(rt[],,nn);
- for (int i=;i<=cnt;i++)
- {
- p=lower_bound(b+,b+nn+,a[i])-b;
- rt[i]=modify(rt[i-],,nn);
- }
- long long ans=;
- for (int i=;i<=cnt;i++)
- {
- x=lower_bound(b+,b+nn+,i)-b;
- if (x==nn+) x--;
- if (b[x]>i) x--;
- if(x==) continue;
- if(min(len[i]+i-,cnt)<i+) continue;
- ans=ans+query(rt[i],rt[min(len[i]+i-,cnt)],,nn,x);
- }
- printf("%lld\n",ans);
- }
- }
Hdu-6230 2017CCPC-哈尔滨站 A.Palindrome Manacher 主席树的更多相关文章
- HDU 4729 An Easy Problem for Elfness (主席树,树上第K大)
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 题意:给出一个带边权的图.对于每一个询问(S , ...
- 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 ...
- 2017中国大学生程序设计竞赛-哈尔滨站 A - Palindrome
Palindrome Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Tota ...
- 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 ...
- 2019CCPC网络赛 C - K-th occurrence HDU - 6704(后缀数组+ST表+二分+主席树)
题意 求区间l,r的子串在原串中第k次出现的位置. 链接:https://vjudge.net/contest/322094#problem/C 思路 比赛的时候用后缀自动机写的,TLE到比赛结束. ...
- 杭电多校HDU 6601 Keen On Everything But Triangle(主席树)题解
题意: 有\(n\)根长度不一的棍子,q次询问,求\([L,R]\)区间的棍子所能组成的周长最长的三角形.棍长\(\in [1, 1e9]\),n\(\in [1, 1e5]\). 思路: 由于不构成 ...
- HDU 6230
Palindrome Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Tota ...
- 2017 ccpc哈尔滨 A题 Palindrome
2017 ccpc哈尔滨 A题 Palindrome 题意: 给一个串\(T\),计算存在多少子串S满足\(S[i]=S[2n−i]=S[2n+i−2](1≤i≤n)\) 思路: 很明显这里的回文串长 ...
- HDU 4417 Super Mario(主席树求区间内的区间查询+离散化)
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
随机推荐
- Deutsch lernen (02)
1. fließend a. 流利的 Meine französische Freundin spricht fließend Deutsch. 流动的 Der Verkehr wickelt ...
- WebForm 登陆test
<script> window.onload = function () { document.getElementById("form1").onsubmit = f ...
- Memcached 之分布式算法原理
memcached并不像mongodb一样可以配置多个节点,并且节点之间可以”自动分配数据“,即相互通信,所以我们在做memcache分布式集群的时候要有一个算法来保证当一台memcache服务器宕机 ...
- esp32使iOS 获取蓝牙外设的Mac地址
最近在做一个需要上下位机的项目,我负责的任务下位机,使用的主控芯片是esp32.这个项目中有一项是需要手机扫描二维码然后连接作为esp32的蓝牙.二维码中包含了mac地址信息,在手机扫描周围设备的时候 ...
- [Usaco2004 Open]Cube Stacking 方块游戏
题面: 约翰和贝茜在玩一个方块游戏.编号为1到n的n(1≤n≤30000)个方块正放在地上.每个构成一个立方柱. 游戏开始后,约翰会给贝茜发出P(1≤P≤100000)个指令.指令有两种 ...
- Solr数据不同步
Solr配置了集群,本地有253和254,2个独立的Solr服务. 同一个页面的图片,刷新2次,图片地址不一样,最后查明,后台数据源Solr1和Solr2的数据不一致. 第1步推测:本地缓存, ...
- Porting from Oracle to MySQL
A potential customer asked my about porting her application from Oracle Database to MySQL. I always ...
- HDU4572 Bottles Arrangement
/* HDU4572 Bottles Arrangement http://acm.hdu.edu.cn/showproblem.php?pid=4572 数论 找规律 题意:有m行n列和1-n的数各 ...
- nutz_web应用中主页跳转到登录页面的方式
一.前言 web应用开发时,地址栏输入ip+port+appName,通常可以跳转到登录页面.以下便介绍我所知道并且验证过的三种跳转方式. 二.准备工作 需要使用到两个url的处理分别如下: @At( ...
- 如何实现网卡bond
https://jingyan.baidu.com/article/375c8e19da666325f2a229f7.html