提交记录 10169


用户 题目 状态 得分 用时 内存 语言 代码长度
Magolor 1006. 【模板题】后缀排序 Accepted 100 35.665 ms 34292 KB C++11 2.59 KB
提交时间 评测时间
2019-08-18 22:47:42 2020-08-01 02:02:50
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100000
#define INF 0x3f3f3f3f
#define c(x,y) t[x].c[y]
#define beg(x) t[x].beg
#define len(x) t[x].len
#define link(x) t[x].link
#define rint register int
inline int rf(){int r;int s=0,c;for(;!isdigit(c=getchar());s=c);for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);return s^45?r:-r;}
#define BUF_SIZE 1000000
#define _END fwrite(_Ob,1,_O-_Ob,stdout), _O = _Ob
#define oc(a) (*_O++ = a)
char _Ob[BUF_SIZE+5], *_O = _Ob, _Os[25], *_Ot;
inline void os(string s){_O += s.copy(_O,s.length(),0), _O-_Ob >= BUF_SIZE-50 ? _END : 0;}
template <typename T> inline void oi(T x)
{
	if(!x){oc('0'); return;} if(x < 0) oc('-'), x = -x;
	for(_Ot = _Os; x; *_Ot++ = x%10+'0', x /= 10);
	for(; _Ot != _Os; oc(*--_Ot)); _O-_Ob >= BUF_SIZE-50 ? _END : 0;
}
struct Node{int c[27],beg,len,link;}t[(MAXN<<1)+5]; int s[MAXN+5], SA[MAXN+5], Rank[MAXN+5], Height[MAXN+5], n, m, tot, last, rem; char str[MAXN+5];
#define New(b,l) (++tot, beg(tot) = b, len(tot) = l, fir[tot] = -1, link(tot) = 1, tot)
struct Edge{int to,nex; Edge(){} Edge(int _to, int _nex):to(_to),nex(_nex){}}e[(MAXN<<2)+5]; int fir[(MAXN<<1)+5], fa[(MAXN<<1)+5], o[(MAXN<<1)+5], book[27], etot, rk;
inline void Add(int a, int b){e[etot] = Edge(b,fir[a]), fir[a] = etot++;}
inline void Append(int x){
	for(int q = (s[++m]=x,++rem,1), nq; rem; last>1?last=link(last):--rem){
		for(; rem > len(c(last,s[m-rem+1])); rem -= len(last=c(last,s[m-rem+1]))); int &p = c(last,s[m-rem+1]);
		if(!p) p = New(m-rem+1,INF), q = link(q) = last; else if(x==s[beg(p)+rem-1]){q = link(q) = last; break;}
		else nq = New(beg(p),rem-1), c(nq,x) = New(m,INF), c(nq,s[beg(p)+=rem-1]) = p, len(p) -= rem-1, q = link(q) = p = nq;
	}
}
void DFS(int p, int d){if(len(p)>n) SA[Rank[beg(p)-d]=rk++] = beg(p)-d; else{d += len(p); for(rint u = fir[p]; ~u; DFS(e[u].to,d), u = e[u].nex);}}
void CalHeight(){for(rint i = 1, L = 0, j; i <= n; Height[Rank[i++]] = L) for(j = SA[~-Rank[i]], L-=L>0; i+L<=n&&j+L<=n&&s[i+L]==s[j+L]; ++L);}
int main(){
	scanf("%s",str+1); n = strlen(str+1); last = ++tot; len(0) = INF; for(rint i = 1; i <= n; Append(str[i]-'a'+1), i++);
	Append(0); for(rint i = 1, j; i <= tot; i++) for(j = 0; j <= 26; c(i,j)?fa[c(i,j)]=i:0, j++); memset(fir+1,-1,tot<<2);
	book[0] = 1; for(rint i = 2; i <= tot; ++book[s[beg(i)]], i++); for(rint i = 1; i <= 26; book[i] += book[i-1], i++);
    for(rint i = tot; i; o[book[s[beg(i)]]--] = i, i--); for(rint i = tot; i>1; Add(fa[o[i]],o[i]), i--); DFS(1,0); CalHeight();
    for(rint i = 1; i <= n; oi(SA[i]), oc(' '), i++); oc('\n');
	for(rint i = 2; i <= n; oi(Height[i]), oc(' '), i++); oc('\n'); _END; return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #136.42 us80 KBAcceptedScore: 0

Subtask #1 Testcase #243.64 us80 KBAcceptedScore: 100

Subtask #1 Testcase #343.3 us80 KBAcceptedScore: 0

Subtask #1 Testcase #440.02 us84 KBAcceptedScore: 0

Subtask #1 Testcase #540.85 us84 KBAcceptedScore: 0

Subtask #1 Testcase #639.25 us84 KBAcceptedScore: 0

Subtask #1 Testcase #723.73 ms20 MB + 196 KBAcceptedScore: 0

Subtask #1 Testcase #835.665 ms30 MB + 240 KBAcceptedScore: 0

Subtask #1 Testcase #932.493 ms26 MB + 492 KBAcceptedScore: 0

Subtask #1 Testcase #1018.467 ms17 MB + 392 KBAcceptedScore: 0

Subtask #1 Testcase #1120.574 ms19 MB + 756 KBAcceptedScore: 0

Subtask #1 Testcase #1218.453 ms33 MB + 500 KBAcceptedScore: 0

Subtask #1 Testcase #1319.418 ms29 MB + 60 KBAcceptedScore: 0

Subtask #1 Testcase #1421.702 ms21 MB + 932 KBAcceptedScore: 0

Subtask #1 Testcase #1529.241 ms30 MB + 60 KBAcceptedScore: 0

Subtask #1 Testcase #1620.975 ms31 MB + 984 KBAcceptedScore: 0

Subtask #1 Testcase #1725.974 ms31 MB + 48 KBAcceptedScore: 0

Subtask #1 Testcase #1826.38 ms30 MB + 892 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2024-04-20 12:14:41 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用