为啥TLE啊,啥事TLE啊。求解答。
只TLE了一个点,很难受,求大佬帮忙,sa做的
//#pragma GCC optimize("Ofast","-funroll-loops","-fdelete-null-pointer-checks")
//#pragma GCC target("ssse3","sse3","sse2","sse","avx2","avx")
#include<bits/stdc++.h>
#define int long long
using namespace std;
int read() {
char ch=getchar();
int f=1,x=0;
while(ch<'0'||ch>'9') {
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9') {
x=x*10+ch-'0';
ch=getchar();
}
return f*x;
}
const int maxn=1e6+10;
int n,sa[maxn],a[maxn],t[maxn],b[maxn],c[maxn],rnk[maxn],m,w[maxn];
string s;
void bucket_sort(int v[]) {
fill(c,c+m+1,0);
for(int i=1;i<=n;i++) {
c[v[i]+1]++;
}
for(int i=1;i<=m;i++) {
c[i]+=c[i-1];
}
for(int i=1;i<=n;i++) {
t[++c[v[sa[i]]]]=sa[i];
}
for(int i=1;i<=n;i++) {
sa[i]=t[i];
}
}
void get_rnk() {
m=0;
for(int i=1;i<=n;i++) {
if(a[sa[i]]!=a[sa[i-1]]||b[sa[i]]!=b[sa[i-1]]) {
m++;
}
rnk[sa[i]]=m;
}
}
void suffix_array() {
for(int i=1;i<=n;i++) {
a[i]=w[i];
b[i]=0;
sa[i]=i;
}
bucket_sort(a);
get_rnk();
for(int l=1;l<n;l<<=1) {
for(int i=1;i<=n;i++) {
a[i]=rnk[i];
if(i+l<=n) {
b[i]=rnk[i+l];
}
else{
b[i]=0;
}
}
bucket_sort(b);
bucket_sort(a);
get_rnk();
}
}
signed main() {
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
n=read();
m=0;
for(int i=1;i<=n;i++) {
char c;
cin>>c;
w[i]=w[n*2-i+1]=(int)c;
m=max(m,w[i]);
}
n<<=1;
suffix_array();
n>>=1;
int l=1,r=n;
for(int i=1;i<=n;i++) {
if(w[l]<w[r]) {
printf("%c",w[l]);
l++;
}
else if(w[l]>w[r]) {
printf("%c",w[r]);
r--;
}
else {
if(rnk[l]<rnk[n*2-r+1]) {
printf("%c",w[l]);
l++;
}
else {
printf("%c",w[r]);
r--;
}
}
if(i%80==0) {
cout<<endl;
}
}
//fclose(stdin);
//fclose(stdout);
return 0;
}