Http://codeforces.com/problemset/problem/159/D
Main topic:
Gives a string that takes the logarithm of two palindrome substrings that are not covered by each other in this string.
Thought: Num[i] represents the left point at the I position of the palindrome string number, and then the tree-like array maintenance sum[i], on behalf of the Palindrome string right end of the palindrome string of less than equals I, total complexity: O (n^2)
1#include <cstdio>2#include <cmath>3#include <algorithm>4#include <cstring>5#include <iostream>6 #definell Long Long7ll c[200005],num[200005];8 intpd[2005][2005],n;9 Chars[200005];Ten intLowbit (intx) { One returnx& (-x); A } - intRead () { - intt=0, f=1;CharCh=GetChar (); the while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} - while('0'<=ch&&ch<='9') {t=t*Ten+ch-'0'; ch=GetChar ();} - returnt*F; - } + voidAddintx) { - for(inti=x;i<=n;i+=lowbit (i)) { +c[i]++; A } at } - intAskintx) { - intres=0; - for(inti=x;i;i-=lowbit (i)) { -res+=C[i]; - } in returnRes; - } to intMain () { +scanf"%s", s+1); -N=strlen (s+1); the for(intI=1; i<=n;i++) *pd[i][i]=1, add (i), num[i]++; $ for(intI=1; i<n;i++)Panax Notoginseng if(s[i]==s[i+1]) pd[i][i+1]++,add (i+1), num[i]++; - for(intlen=3; len<=n;len++) the for(intI=1; i+len-1<=n;i++){ + intj=i+len-1; A if(pd[i+1][j-1]&&S[I]==S[J]) pd[i][j]=1, add (j), num[i]++; the } +ll ans=0; - for(intI=1; i<=n;i++) $Ans+=ask (I-1)*( ll) (Num[i]); $printf"%i64d\n", ans); - return 0; -}
Codeforces 159D palindrome Pairs