hdu5371 Manacher + line Tree

Source: Internet
Author: User

The problem is to find out an array string 3 equal to the first part and the 3rd part, the second part and the first part palindrome, then calculate these strings to ask such a string maximum, we first use manacher to calculate each position to the axis of symmetry to the left end of the longest palindrome radius added to the first position Palindrome radius is d[i], then he can affect the range of d[i]-i to I if he is the biggest then the answer is I-j (j for [D[i]-i,i] the number between), we can then appropriate point to add the effect of this position in the line segment tree, Then, at the end of the line tree, find out what the maximum value of this interval is.

#include <iostream>#include<algorithm>#include<cstdio>#include<string.h>#include<vector>using namespacestd;Const intmaxn=100005;intSTR[MAXN];ints[maxn*2];intrad[maxn*2];//The radius of the palindrome string centered on Iinth[maxn],to[maxn],nx[maxn],numofedg;intD[MAXN];voidADDEDG (intUintv) {     ++NUMOFEDG; To[numofedg]=v; Nx[numofedg]=h[u]; h[u]=numofedg;}voidManacher (intLen) {     intCur=1; s[0]=-1;  for(intI=0; i<len; i++) {S[cur++]=Str[i]; S[cur++]=-1; } rad[0]=1; intId=0;  for(intI=1; i<cur; i++)        {            if(rad[id]+id>i) Rad[i]=min (rad[2*id-i],rad[id]+id-i); Elserad[i]=1;  while(i-rad[i]>=0&&i+rad[i]<cur&&s[I-rad[i]] = = s[I+rad[i]) rad[i]++; if(Id+rad[i]<i+rad[i]) id=i; }      for(intI=1; i<=len; i++) {D[i]=rad[i*2]/2; if(d[i]==0)Continue; ADDEDG (i-d[i],i); }}structitree{intLoc,cl,cr,ans; intval[maxn*4]; voidBuildintLintRinto) {Val[o]=0; if(L==R)return ; intMid= (l+r) >>1; Build (L,mid,o*2); Build (Mid+1, r,o*2+1); }      voidUpdateintLintRinto) {if(l==R) {Val[o]=l;return ; }           intMid= (l+r) >>1; if(loc<=mid) Update (l,mid,o*2); ElseUpdate (mid+1, r,o*2+1); Val[o]=max (val[o*2],val[o*2+1]); }     voidQueryintLintRinto) {if(cl<=l&&r<=CR) {ans=max (Ans,val[o]);return; }         intMid= (l+r) >>1; if(cl<=mid) query (l,mid,o*2); if(cr>mid) query (mid+1, r,o*2+1); }}t;intMain () {intCAs; scanf ("%d",&CAs);  for(intCc=1; cc<=cas; Cc++)   {       intN; scanf ("%d",&N); h[0]=0; numofedg=0;  for(intI=0; i<n; i++) {H[i+1]=0; scanf ("%d",&Str[i]);       } manacher (n); intans=0; T.build (1N1); d[0]=0;  for(intI=0; i<n; i++)        {              for(intJ=h[i]; J j=Nx[j]) {T.loc=TO[J]; T.update (1N1); } t.cl=i+1; t.cr=d[i]+i; if(T.CL&GT;T.CR)Continue; T.ans=0; T.query (1N1); Ans=max (ans,t.ans-i); } printf ("Case #%d:%d\n", cc,ans*3); }    return 0;}
View Code

hdu5371 Manacher + line Tree

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.