POI2010ANT-Antisymmetry

Posted shxnb666

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POI2010ANT-Antisymmetry相关的知识,希望对你有一定的参考价值。

题面

https://www.luogu.org/problem/P3501

题解

#include<cstdio>
#include<iostream>
#include<cstring>
#define ri register int
#define N 500050
#define uLL unsigned long long
using namespace std;
int n;
char s[N];
const uLL p=107;
uLL sum1[N],sum2[N];
uLL pp[N];
uLL getv1(int l,int r) 
  return sum1[r]-sum1[l-1]*pp[r-l+1];

uLL getv2(int l,int r)
  return sum2[l]-sum2[r+1]*pp[r-l+1];


int main()
  pp[0]=1;
  for (ri i=1;i<N;i++) pp[i]=pp[i-1]*p;
  scanf("%d",&n);
  scanf("%s",s+1);
  for (ri i=1;i<=n;i++) sum1[i]=sum1[i-1]*p+(s[i]-0);
  for (ri i=n;i>=1;i--) sum2[i]=sum2[i+1]*p+((s[i]-0)^1);
  uLL ans=0;
  for (ri i=1;i<=n;i++) if (((s[i]-0)^(s[i+1]-0))==1) 
    int lb=1,rb=min(i-1,n-i-1),ret=0;
    while (lb<=rb) 
      int mid=(lb+rb)/2;
      if (getv1(i-mid,i)==getv2(i+1,i+mid+1)) ret=mid,lb=mid+1; else rb=mid-1;
    
    ans+=ret+1;
  
  cout<<ans<<endl;

 

以上是关于POI2010ANT-Antisymmetry的主要内容,如果未能解决你的问题,请参考以下文章

BZOJ 2086: [Poi2010]Blocks

BZOJ 2086: [Poi2010]Blocks

bzoj2084[Poi2010]Antisymmetry

BZOJ 2084: [Poi2010]Antisymmetry

BZOJ2096: [Poi2010]Pilots

洛谷 P3496 [POI2010]GIL-Guilds