数据有问题?开O2就可以过了

P3809 【模板】后缀排序

```cpp #include<bits/stdc++.h> #define maxn 1000050 using namespace std; char s[maxn]; int n,m; int a[maxn],rank[maxn],sa[maxn],c[maxn],x[maxn],y[maxn]; void da() { for(int i=1; i<=n; i++) c[x[i]=a[i]]++; for(int i=1; i<=m; i++) c[i]+=c[i-1]; for(int i=n; i>=1; i--) sa[c[x[i]]--]=i; for(int w=1,num; num<n && w <= n; w<<=1) { num=0; for(int i=n-w+1; i<=n; i++) y[++num]=i; for(int i=1; i<=n; i++) if(sa[i] > w) y[++num]=sa[i]-w; for(int i=1; i<=m; i++) c[i]=0; for(int i=1; i<=n; i++) ++c[x[i]]; for(int i=1; i<=m; i++) c[i]+=c[i-1]; for(int i=n; i>=1; i--) { sa[c[x[y[i]]]--]=y[i]; y[i]=0; } swap(x,y); x[sa[1]]=1; num=1; for(int i=2; i<=n; i++) x[sa[i]]=(y[sa[i]] == y[sa[i-1]] && y[sa[i]+w] == y[sa[i-1]+w]) ? num : ++num; m=num; } } int main() { freopen("s.in","r",stdin); // freopen("s.out","w",stdout); gets(s+1); n=strlen(s+1); m=127; for(int i=1; i<=n; i++) a[i]=s[i]-48; da(); for(int i=1; i<=n; i++) cout<<sa[i]<<" "; return 0; } ```
by Eagle_WYX @ 2018-06-15 22:06:14


求教,要死
by Eagle_WYX @ 2018-06-15 22:06:38


@[Eagle_WYX](/space/show?uid=45700) 这只能说明你数组越界了
by gorokokoro @ 2018-06-15 22:06:41


@[Ghastlcon](/space/show?uid=34354) 不是数组越界
by Eagle_WYX @ 2018-06-15 22:08:38


@[Ghastlcon](/space/show?uid=34354) 是。。。。num没有初值。。。乱码有时候会大于n。。。刚刚调出来,呜呜呜一晚上没了。 谢谢啦
by Eagle_WYX @ 2018-06-15 22:09:44


真是一个会发癫的程序。。。
by Eagle_WYX @ 2018-06-15 22:10:22


@[Eagle_WYX](/space/show?uid=45700) 所以,不要随便质疑有2k人通过的题目
by 1124828077ccj @ 2018-06-16 09:26:08


@[陈常杰](/space/show?uid=14738) 哈哈,谢谢啦,不过。。。不能删帖吗?尴尬ovo
by Eagle_WYX @ 2018-06-16 15:54:57


|