提交记录 12705


用户 题目 状态 得分 用时 内存 语言 代码长度
Shiina_Mashiro 1006. 【模板题】后缀排序 Wrong Answer 0 8.865 ms 5108 KB C++11 2.01 KB
提交时间 评测时间
2020-05-08 14:54:51 2020-08-01 02:57:53
#include<cstdio>
#include<cstring>
#include<bitset>
#include<algorithm>
#include<numeric>
using std::partial_sum;
using std::transform;
using std::for_each;
namespace IO
{
    char obuf[(1<<21)+1],st[11],*oS=obuf,*oT=obuf+(1<<21);
    void Flush(){fwrite(obuf,1,oS-obuf,stdout),oS=obuf;}
    void Put(char x){*oS++=x;if(oS==oT)Flush();}
    void write(int x){int top=0;if(!x)Put('0');while(x)st[++top]=(x%10)+48,x/=10;while(top)Put(st[top--]);Put(' ');}
}using namespace IO;
const int N=1000007;
char str[N+10];int sa[N],rank[N],h[N],s[N<<1],t[N<<1],pos[N<<1],r[N>>1],c[N>>1];
#define is(x,a) sa[r[s[x]]a]=x
#define IS(S)\
    memset(sa+1,0,n<<2),memset(c+1,0,m<<2),for_each(s+1,s+n+1,[](int x){++c[x];}),partial_sum(c+1,c+m+1,c+1),memcpy(r+1,c+1,m<<2);\
    for(int i=N;i;--i) is(S[i],--);\
    transform(c,c+m,r+1,[](int x){return x+1;});\
    for(int i=1;i<=n;++i) if(sa[i]>1&&t[sa[i]-1]) is(sa[i]-1,++);\
    memcpy(r+1,c+1,m<<2);\
    for(int i=n;i;--i) if(sa[i]>1&&!t[sa[i]-1]) is(sa[i]-1,--);
void SAIS(int n,int m,int*s,int*t,int*pos)
{
    int N=0,M=rank[1]=0,*S=s+n;
    t[n]=0;
    for(int i=n-1;i;--i) t[i]=s[i]^s[i+1]? s[i]>s[i+1]:t[i+1];
    for(int i=2;i<=n;++i) rank[i]=t[i-1]&&!t[i]? pos[++N]=i,N:0;
    IS(pos);
    for(int i=1,x,y=0;i<=n;++i)
	if((x=rank[sa[i]]))
	{
	    if(M<=1||pos[x+1]-pos[x]!=pos[y+1]-pos[y]) ++M;
	    else for(int a=pos[x],b=pos[y];a<=pos[x+1];++a,++b) if((s[a]<<1|t[a])^(s[b]<<1|t[b])) {++M;break;}
	    S[y=x]=M;
	}
    if(M^N) SAIS(N,M,S,t+n,pos+n); else for(int i=1;i<=N;++i) sa[S[i]]=i;
    for(int i=1;i<=N;++i) S[i]=pos[sa[i]];
    IS(S);
}
int main()
{
    int n;
    fread(str+1,1,1000000,stdin),n=strlen(str+1);
    while(!isalpha(str[n])) --n;
    transform(str+1,str+n+1,s+1,[](char c){return c-'a'+2;}),s[++n]=1,SAIS(n--,27,s,t,pos);
    for(int i=1;i<=n;++i) rank[sa[i]=sa[i+1]]=i;
    for(int i=1,j,l=0;i<=n;h[rank[i++]]=l) for(j=sa[~-rank[i]],l-=l>0;i+l<=n&&j+l<=n&&s[i+l]==s[j+l];++l);
    for_each(sa+1,sa+n+1,[](int x){write(x);}),Put('\n'),for_each(h+2,h+n+1,[](int x){write(x);}),Flush();
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #19.89 us52 KBWrong AnswerScore: -100

Subtask #1 Testcase #211.22 us52 KBAcceptedScore: 100

Subtask #1 Testcase #311.7 us52 KBAcceptedScore: 0

Subtask #1 Testcase #410.9 us52 KBAcceptedScore: 0

Subtask #1 Testcase #511.32 us52 KBAcceptedScore: 0

Subtask #1 Testcase #610.58 us52 KBAcceptedScore: 0

Subtask #1 Testcase #77.805 ms4 MB + 196 KBAcceptedScore: 0

Subtask #1 Testcase #88.865 ms4 MB + 400 KBAcceptedScore: 0

Subtask #1 Testcase #98.783 ms4 MB + 168 KBAcceptedScore: 0

Subtask #1 Testcase #105.602 ms2 MB + 744 KBAcceptedScore: 0

Subtask #1 Testcase #115.389 ms2 MB + 780 KBAcceptedScore: 0

Subtask #1 Testcase #125.183 ms4 MB + 300 KBAcceptedScore: 0

Subtask #1 Testcase #135.207 ms4 MB + 236 KBAcceptedScore: 0

Subtask #1 Testcase #145.742 ms3 MB + 864 KBAcceptedScore: 0

Subtask #1 Testcase #155.766 ms3 MB + 928 KBAcceptedScore: 0

Subtask #1 Testcase #166.504 ms4 MB + 892 KBAcceptedScore: 0

Subtask #1 Testcase #175.584 ms4 MB + 1012 KBAcceptedScore: 0

Subtask #1 Testcase #186.448 ms4 MB + 980 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-03-25 14:50:33 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠