POJ-3415-Common Substrings

罗大神论文里面的题目,膜拜~~~

参考了下网上的神牛,栈优化膜拜~

代码:

#include
#include
#include
using namespace std;
const int maxn=(1e5+1000)*2;
int n,k,len,lena,wa[maxn],wb[maxn],wu[maxn],wv[maxn],sa[maxn],rank[maxn],height[maxn],pos[maxn],top;
long long sum[3],val[maxn],ans;
char r[maxn],str[maxn];
int cmp(int *r,int a,int b,int l)
{
    return r[a]==r[b]&&r[a+l]==r[b+l];
}
void da(int n,int m)
{
    int i,j,p,*x=wa,*y=wb,*t;
    for(i=0;i=0;i--)
	sa[--wu[x[i]]]=i;
    for(j=1,p=1;p=j)
		y[p++]=sa[i]-j;
	for(i=0;i=0;i--)
	    sa[--wu[wv[i]]]=y[i];
	for(t=x,x=y,y=t,p=1,x[sa[0]]=0,i=1;i=0&&val[j]>height[i]-k+1;j--)
		{
		    sum[pos[j]]+=height[i]-k+1-val[j];
		    val[j]=height[i]-k+1;
		}
		val[top]=height[i]-k+1;
		int t;
		if(sa[i-1]>len)
		    pos[top]=1;
		else
		    pos[top]=0;
		sum[pos[top++]]+=height[i]-k+1;
		if(sa[i]>len)
		    t=1;
		else
		    t=0;
		ans+=sum[t^1];
	    }
	}
	printf("%I64d\n",ans);
    }
    return 0;
}


你可能感兴趣的:(ACM,POJ)