本地#2能过,交上去却wa
查看原帖
本地#2能过,交上去却wa
308464
奇米楼主2020/6/16 11:01
#include <bits/stdc++.h>
#define For(i,a,b) for ( int i=(a);i<=(b);i++ )
#define Dow(i,b,a) for ( int i=(b);i>=(a);i-- )
#define GO(i,x) for ( int i=head[x];i;i=e[i].nex )
#define mem(x,s) memset(x,s,sizeof(x))
#define cpy(x,s) memcpy(x,s,sizeof(x))
#define YES return puts("YES"),0
#define NO return puts("NO"),0
#define GG return puts("-1"),0
#define pb push_back
using namespace std;

inline int read()
{
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}

const int mod=1e9+7;
const int mo=998244353;
const int N=1e6+5;

int n,m,x[N],y[N],SA[N],ton[512];
char ch[N];

inline void getSA()
{
	For(i,1,n) ton[x[i]=ch[i]]++;
	For(i,2,m) ton[i]+=ton[i-1];
	Dow(i,n,1) SA[ton[x[i]]--]=i;
	for ( int k=1;k<=n;k<<=1 ) 
	{
		int cnt=0;
		For(i,n-k+1,n) y[++cnt]=i;
		For(i,1,n) if(SA[i]>k) y[++cnt]=SA[i]-k;
		For(i,1,m) ton[i]=0;
		For(i,1,n) ton[x[i]]++;
		For(i,2,m) ton[i]+=ton[i-1];
		Dow(i,n,1) SA[ton[x[y[i]]]--]=y[i],y[i]=0;
		swap(x,y);
		x[SA[1]]=1; cnt=1;
		For(i,2,n) x[SA[i]]=(y[SA[i]]==y[SA[i-1]]&&y[SA[i]+k]==y[SA[i-1]+k])?cnt:++cnt;
		if(cnt==n) break;
		m=cnt;
	}
	For(i,1,n) printf("%d ",SA[i]); 
}

int main()
{
	scanf("%s",ch+1);
	m=122;
	n=strlen(ch+1);
	getSA();
	return 0;
}

2020/6/16 11:01
加载中...