2084: [poi2010] antisypolicrytime limit: 10 sec memory limit: 259 MB
Submit: 187 solved: 125
[Submit] [Status] Description
For a 01 string, if the string 0 and 1 are reversed and the entire string is reversed like the original string, it is called the "anti-Claim" string. For example, 00001111 and 010101 are called objections, and 1001 is not.
The following code returns a 01 string with a length of N and calculates the number of substrings that are called back.
Input
The first line is a positive integer n (n <= 500,000 ). The second line is a string of 01 characters whose length is N.
Output
A positive integer that indicates the number of substrings that are not called.
Sample input8
11001011
Sample output7
Hint
The seven opposing sub-strings are: 01 (appear twice), 10 (appear twice), 0101,110 0, and 001011
Hint Source
Thanks to jzp
Question:
At the beginning, YY had a hash, flipped S and reversed it as SS. For each position I, find s [I .. what is the LCP of N] and SS [n-I + 2, N?
What does nlogn look like?
Today, I suddenly found out that this is not a manacher?
Then YY, and no separator is added...
The zhonghaoxi code was decisively worshipped:
1 scanf("%s",s+1);2 for1(i,n)st[i<<1]=(s[i]==‘0‘?0:2);3 n<<=1;n++;4 for(int i=1;i<=n;i+=2)st[i]=1;
mx=id=0; for(int i=1;i<=n;i+=2) { if(mx>i)p[i]=min(p[2*id-i],mx-i);else p[i]=1; for(;i-p[i]>0&&i+p[i]<=n&&st[i-p[i]]+st[i+p[i]]==2;p[i]++); if(p[i]+i>mx)mx=p[i]+i,id=i; }
No more orz. The manacher algorithm is too flexible,
st[i-p[i]]+st[i+p[i]]==2
This equivalence relationship can also be passed, and we can only find the longest return string centered on the separator. Orzzzzzzzz
The manacher algorithm is mainly used to reduce redundant computing and make full use of previously computed information.
Also, pay attention to Boundary Control and irrelevant character settings.
Code:
1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #include<set>10 #include<queue>11 #include<string>12 #define inf 100000000013 #define maxn 2000000+100014 #define maxm 500+10015 #define eps 1e-1016 #define ll long long17 #define pa pair<int,int>18 #define for0(i,n) for(int i=0;i<=(n);i++)19 #define for1(i,n) for(int i=1;i<=(n);i++)20 #define for2(i,x,y) for(int i=(x);i<=(y);i++)21 #define for3(i,x,y) for(int i=(x);i>=(y);i--)22 #define mod 100000000723 using namespace std;24 inline int read()25 {26 int x=0,f=1;char ch=getchar();27 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}28 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}29 return x*f;30 }31 int n,st[maxn],p[maxn],mx,id;32 char s[maxn];33 int main()34 {35 freopen("input.txt","r",stdin);36 freopen("output.txt","w",stdout);37 n=read();38 scanf("%s",s+1);39 for1(i,n)st[i<<1]=(s[i]==‘0‘?0:2);40 n<<=1;n++;41 for(int i=1;i<=n;i+=2)st[i]=1;42 mx=id=0;43 for(int i=1;i<=n;i+=2)44 {45 if(mx>i)p[i]=min(p[2*id-i],mx-i);else p[i]=1;46 for(;i-p[i]>0&&i+p[i]<=n&&st[i-p[i]]+st[i+p[i]]==2;p[i]++);47 if(p[i]+i>mx)mx=p[i]+i,id=i;48 }49 ll ans=0;50 for(int i=1;i<=n;i+=2)ans+=(p[i]-1)>>1;51 printf("%lld\n",ans);52 return 0;53 }View code
Bzoj2084: [poi2010] antisyry ry