提交记录 17466


用户 题目 状态 得分 用时 内存 语言 代码长度
AntiLeaf 1006. 【模板题】后缀排序 Accepted 100 36.129 ms 3940 KB C++11 1.60 KB
提交时间 评测时间
2022-03-06 20:31:00 2022-03-06 20:31:04
#include <bits/stdc++.h>

using namespace std;

constexpr int maxn = 100005;

void get_sa(char *s, int n, int *sa, int *rnk, int *height) { // 1-base
	static int buc[maxn], id[maxn], p[maxn], t[maxn * 2];

	int m = 300;
	
	for (int i = 1; i <= n; i++)
		buc[rnk[i] = s[i]]++;
	for (int i = 1; i <= m; i++)
		buc[i] += buc[i - 1];
	for (int i = n; i; i--)
		sa[buc[rnk[i]]--] = i;
	
	memset(buc, 0, sizeof(int) * (m + 1));
	
	for (int k = 1, cnt = 0; cnt != n; k *= 2, m = cnt) {
		cnt = 0;
		for (int i = n; i > n - k; i--)
			id[++cnt] = i;
		
		for (int i = 1; i <= n; i++)
			if (sa[i] > k)
				id[++cnt] = sa[i] - k;
		
		for (int i = 1; i <= n; i++)
			buc[p[i] = rnk[id[i]]]++;
		for (int i = 1; i <= m; i++)
			buc[i] += buc[i - 1];
		for (int i = n; i; i--)
			sa[buc[p[i]]--] = id[i];
		
		memset(buc, 0, sizeof(int) * (m + 1));
		
		memcpy(t, rnk, sizeof(int) * (max(n, m) + 1));

		cnt = 0;
		for (int i = 1; i <= n; i++) {
			if (t[sa[i]] != t[sa[i - 1]] || t[sa[i] + k] != t[sa[i - 1] + k])
				cnt++;
			
			rnk[sa[i]] = cnt;
		}
	}

	for (int i = 1; i <= n; i++)
		sa[rnk[i]] = i;
	
	for (int i = 1, k = 0; i <= n; i++) {
		if (k)
			k--;

		while (s[i + k] == s[sa[rnk[i] - 1] + k])
			k++;

		height[rnk[i]] = k; // height[i] = lcp(sa[i], sa[i - 1])
	}
}

char s[maxn];
int sa[maxn], rnk[maxn], height[maxn];

int main() {
	ios::sync_with_stdio(false);

	cin >> (s + 1);

	int n = strlen(s + 1);

	get_sa(s, n, sa, rnk, height);

	for (int i = 1; i <= n; i++)
		cout << sa[i] << (i < n ? ' ' : '\n');
	
	for (int i = 2; i <= n; i++)
		cout << height[i] << (i < n ? ' ' : '\n');

if (n == 1) cout << "\n";

	
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #142.71 us96 KBAcceptedScore: 0

Subtask #1 Testcase #249.79 us96 KBAcceptedScore: 100

Subtask #1 Testcase #349.76 us96 KBAcceptedScore: 0

Subtask #1 Testcase #447.32 us100 KBAcceptedScore: 0

Subtask #1 Testcase #546.85 us96 KBAcceptedScore: 0

Subtask #1 Testcase #645.19 us100 KBAcceptedScore: 0

Subtask #1 Testcase #720.124 ms3 MB + 564 KBAcceptedScore: 0

Subtask #1 Testcase #836.129 ms3 MB + 784 KBAcceptedScore: 0

Subtask #1 Testcase #922.308 ms3 MB + 652 KBAcceptedScore: 0

Subtask #1 Testcase #1014.361 ms2 MB + 432 KBAcceptedScore: 0

Subtask #1 Testcase #1115.096 ms2 MB + 472 KBAcceptedScore: 0

Subtask #1 Testcase #1227.305 ms3 MB + 848 KBAcceptedScore: 0

Subtask #1 Testcase #1326.109 ms3 MB + 868 KBAcceptedScore: 0

Subtask #1 Testcase #1423.518 ms3 MB + 680 KBAcceptedScore: 0

Subtask #1 Testcase #1523.245 ms3 MB + 684 KBAcceptedScore: 0

Subtask #1 Testcase #1627.327 ms3 MB + 848 KBAcceptedScore: 0

Subtask #1 Testcase #1727.054 ms3 MB + 848 KBAcceptedScore: 0

Subtask #1 Testcase #1827.268 ms3 MB + 848 KBAcceptedScore: 0


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