Codeforces 159D palindrome Pairs

Source: Internet
Author: User

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]&AMP;&AMP;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

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.