1.做后缀数组
for(int i=0;i<strlen(s);i++)
然后tle了一个晚上。。真是花样作死。。。strlen是o(n)的,,,想想也是这玩意又不是针对stl容器的。。不过是个普通的数组
2.回文自动机牢记先写fail失陪边,再往下建边
struct pam
{ intcnt,last;
intfail[maxn],l[maxn];
pam(){
cnt=1;fail[0]=fail[1]=1;l[1]=-1;
g[1].pb(0);
}
voidextend(int c,int n)
{int p=last;
while(s[n]!=s[n-l[p]-1])
{ p=fail[p];}
if(!a[p][c])
{cnt++;int k=fail[p];
l[cnt]=l[p]+2;
while(s[n]!=s[n-l[k]-1]) k=fail[k];
fail[cnt]=a[k][c]; a[p][c]=cnt;//这两句话千万不要写反了。因为在边界情况下写反会出问题。。。具体问题要认真调试才好分析。。。反正记牢就好
g[fail[cnt]].pb(cnt);
}
last=a[p][c];
}
}pam;
3.set和multiset是针对cmp函数而言的
struct cmp
{ bool operator ()(const int x,const int y) const
{return depth[x]>depth[y];}
};
multiset<int,cmp> tree; //如果这里用了set。那么就只能存每个深度的节点各一个了
4.rope尽量优化空间
- rope<int> *fa[maxn];
- int a[maxn];//int *a;
- int find(int i,int x)
- { if(x!=fa[i]->at(x))
- { int f=find(i,fa[i]->at(x));
- if(f==fa[i]->at(x)) return f;//本来这句话可以不加。但是因为replace有空间开销(自己猜测)所以这样可以省点空间的样子
- fa[i]->replace(x,f);
- return f;
- }
- return x;
- }