提交记录 17646


用户 题目 状态 得分 用时 内存 语言 代码长度
SocialZxy 1006. 【模板题】后缀排序 Accepted 100 57.752 ms 10164 KB C++ 1.37 KB
提交时间 评测时间
2022-04-13 10:46:28 2022-04-13 10:46:33
#include<bits/stdc++.h>
using namespace std;

int get() {
	int x = 0, f = 1; char c = getchar();
	while(!isdigit(c)) { if(c == '-') f = -1; c = getchar(); }
	while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); }
	return x * f;
}

const int N = 1e6 + 5;
int n, m;
char s[N];
int sa[N], rk[N], ht[N], cnt[N], id[N], p;

void GetSA() {
	m = 300;
	for(int i = 1; i <= n; i++) ++cnt[rk[i] = s[i]];
	for(int i = 1; i <= m; i++) cnt[i] += cnt[i - 1];
	for(int i = n; i >= 1; i--) sa[cnt[rk[i]]--] = i;
	for(int w = 1; w < n && p < n; w <<= 1, m = p) {
		p = 0;
		for(int i = n - w + 1; i <= n; i++) id[++p] = i;
		for(int i = 1; i <= n; i++) if(sa[i] > w) id[++p] = sa[i] - w;
		for(int i = 1; i <= m; i++) cnt[i] = 0;
		for(int i = 1; i <= n; i++) ++cnt[rk[i]];
		for(int i = 1; i <= m; i++) cnt[i] += cnt[i - 1];
		for(int i = n; i >= 1; i--) sa[cnt[rk[id[i]]]--] = id[i], id[i] = 0;
		swap(id, rk), rk[sa[1]] = p = 1;
		for(int i = 2; i <= n; i++)
			rk[sa[i]] = (id[sa[i]] == id[sa[i - 1]] && id[sa[i] + w] == id[sa[i - 1] + w])? p : ++p;
	}
}

void GetHeight() {
	for(int i = 1, k = 0; i <= n; i++) {
		if(k) --k;
		while(s[i + k] == s[sa[rk[i] - 1] + k]) ++k;
		ht[rk[i]] = k;
	}
}

int main() {
	scanf("%s", s + 1), n = strlen(s + 1);
	GetSA();
	GetHeight();
	for(int i = 1; i <= n; i++) printf("%d ", sa[i]); printf("\n");
	for(int i = 2; i <= n; i++) printf("%d ", ht[i]); printf("\n");
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #135.87 us64 KBAcceptedScore: 0

Subtask #1 Testcase #21.57 ms7 MB + 696 KBAcceptedScore: 100

Subtask #1 Testcase #31.571 ms7 MB + 696 KBAcceptedScore: 0

Subtask #1 Testcase #42.906 ms7 MB + 696 KBAcceptedScore: 0

Subtask #1 Testcase #52.904 ms7 MB + 696 KBAcceptedScore: 0

Subtask #1 Testcase #62.908 ms7 MB + 696 KBAcceptedScore: 0

Subtask #1 Testcase #732.558 ms9 MB + 644 KBAcceptedScore: 0

Subtask #1 Testcase #857.752 ms9 MB + 864 KBAcceptedScore: 0

Subtask #1 Testcase #936.13 ms9 MB + 736 KBAcceptedScore: 0

Subtask #1 Testcase #1024.945 ms9 MBAcceptedScore: 0

Subtask #1 Testcase #1126.392 ms9 MB + 40 KBAcceptedScore: 0

Subtask #1 Testcase #1249.607 ms9 MB + 928 KBAcceptedScore: 0

Subtask #1 Testcase #1347.12 ms9 MB + 948 KBAcceptedScore: 0

Subtask #1 Testcase #1438.851 ms9 MB + 764 KBAcceptedScore: 0

Subtask #1 Testcase #1538.499 ms9 MB + 764 KBAcceptedScore: 0

Subtask #1 Testcase #1648.377 ms9 MB + 928 KBAcceptedScore: 0

Subtask #1 Testcase #1748.009 ms9 MB + 928 KBAcceptedScore: 0

Subtask #1 Testcase #1848.218 ms9 MB + 928 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2024-11-22 18:46:04 | Loaded in 2 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠