Manacher algorithm
Ah ... Manacher Modify a bit ~ ~ Water ...
Manacher originally is to find the same sub-string, namely Palindrome string, we are here to find the corresponding location of the "anti-palindrome string" (against the claim? 233)
The length of the odd is definitely not satisfying >_> (the middle that character does not oppose anyway)
Then we'll find the ' # ' as the center ...
Change the judging condition a[i-p[i]-1]==a[i+p[i]+1] to "unequal ... Or two of them are ' # '.
Add up all the p[i, that is, the length of all the "anti-palindrome strings" plus divided by two is the answer ~
See the Code Bar >_<
1 /**************************************************************2 problem:20843 User:tunix4 language:c++5 result:accepted6 time:68 Ms7 memory:9572 KB8 ****************************************************************/9 Ten //Bzoj 2084 One#include <vector> A#include <cstdio> -#include <cstring> -#include <cstdlib> the#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) - #defineF (i,j,n) for (int i=j;i<=n;++i) + #defineD (i,j,n) for (int i=j;i>=n;--i) - #definePB Push_back + using namespacestd; AtypedefLong LongLL; atInlineintGetint () { - intR=1, v=0;CharCh=GetChar (); - for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') r=-1; - for(; isdigit (ch); Ch=getchar ()) v=v*Ten+ch-'0'; - returnr*v; - } in Const intn=5e5+Ten, inf=~0u>>2; - /*******************template********************/ to CharS[n]; + inta[n<<1],p[n<<1]; - intMain () { the intn=getint (); *scanf"%s", s); $F (I,1, N) a[i<<1]=s[i-1];Panax Notoginsengn=n<<1|1; - intId=0, ans=0; theF (I,1, N) { + if(a[i]!=0)Continue; A if(p[id]+id>i) P[i]=min (p[2*id-i],p[id]+id-i); the Elsep[i]=0; + while(i-p[i]-1>0&& i+p[i]+1<=n && -(a[i-p[i]-1]!=a[i+p[i]+1] || a[i-p[i]-1]==0)) p[i]++; $ if(P[i]+i>p[id]+id) id=i; $ans+=P[i]; - } -printf"%d\n", ans/2); the return 0; -}
View Code 2084: [poi2010]antisymmetry time limit:10 Sec Memory limit:259 MB
submit:247 solved:162
[Submit] [Status] [Discuss] Description
For a 01 string, if the string 0 and 1 are reversed, then the entire string, in turn, is the same as the original string, called the "anti-call" string. For example, 00001111 and 010101 are against, 1001 is not.
Now give a 01 string with a length of N, and ask how many substrings it is against.
Input
The first line is a positive integer n (n <= 500,000). The second line is a 01 string of length N.
Output
A positive integer that represents the number of counter-called substrings.
Sample Input8
11001011
Sample Output7
Hint
7 opposing substrings are: 01 (appearing two times), 10 (appearing two times), 0101, 1100 and 001011
Hintsource
Acknowledgement JZP
[Submit] [Status] [Discuss]
"Bzoj" "2084" "POI2010" antisymmetry