提交记录 3380


用户 题目 状态 得分 用时 内存 语言 代码长度
panda_2134 1006. 【模板题】后缀排序 Wrong Answer 0 55.162 ms 34096 KB C++ 1.87 KB
提交时间 评测时间
2018-07-14 18:29:32 2020-07-31 21:16:20
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <algorithm>

using namespace std;

const int MAXN = 8e6, SIGMA = 128; // ascii 0 - 127

struct SuffixArray {
    
    int sa[MAXN + 10], buf[3][MAXN + 10], c[SIGMA + 10], rk[MAXN + 10], height[MAXN + 10];
    
    void build_sa(char *str) {
        int n = strlen(str) + 1, m = SIGMA, p = 0;
        int *x = buf[0], *y = buf[1];
        
        for(int i = 0; i < m; i++) c[i] = 0;
        for(int i = 0; i < n; i++) ++c[x[i] = str[i]];
        for(int i = 1; i < m; i++) c[i] += c[i-1];
        for(int i = n-1; i >= 0; i--) sa[--c[x[i]]] = i;
        for(int k = 1; k <= n; k <<= 1) {
            p = 0;
            
            for(int i = n-k; i < n; i++) y[p++] = i;
            for(int i = 0; i < n; i++) if(sa[i] >= k) y[p++] = sa[i] - k;
            
            for(int i = 0; i < m; i++) c[i] = 0;
            for(int i = 0; i < n; i++) ++c[x[y[i]]];
            for(int i = 1; i < m; i++) c[i] += c[i-1];
            for(int i = n-1; i >= 0; i--) sa[--c[x[y[i]]]] = y[i];
            
            swap(x, y);
            p = 1, x[sa[0]] = 0;
            for(int i = 1; i < n; i++)
                x[sa[i]] = (y[sa[i]] == y[sa[i-1]] and y[sa[i]+k] == y[sa[i-1]+k]) ? p-1 : p++;
            
            if(p == n) break;
            else m = p;
        }
        
        memcpy(rk, x, sizeof(rk));
        int k = 0;
        for(int i = 0; i < n; i++) {
            if(k) k--;
            if(!rk[i]) continue;
            int j = sa[rk[i]-1];
            while(str[i+k] == str[j+k]) k++;
            height[rk[i]] = k;
        }
    }
} sa;

int len;
char buf[MAXN + 10];

int main() {
    scanf("%s", buf); len = strlen(buf);
    sa.build_sa(buf);
    for(int i = 1; i <= len; i++)
        printf("%d ", sa.sa[i] + 1);
    putchar(10);
    for(int i = 2; i <= len; i++)
		printf("%d ", sa.height[i]);
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #17.898 ms30 MB + 568 KBWrong AnswerScore: -100

Subtask #1 Testcase #27.925 ms30 MB + 568 KBAcceptedScore: 100

Subtask #1 Testcase #37.921 ms30 MB + 568 KBAcceptedScore: 0

Subtask #1 Testcase #47.915 ms30 MB + 568 KBAcceptedScore: 0

Subtask #1 Testcase #57.903 ms30 MB + 568 KBAcceptedScore: 0

Subtask #1 Testcase #67.891 ms30 MB + 568 KBAcceptedScore: 0

Subtask #1 Testcase #738.657 ms32 MB + 948 KBAcceptedScore: 0

Subtask #1 Testcase #855.162 ms33 MB + 112 KBAcceptedScore: 0

Subtask #1 Testcase #940.829 ms32 MB + 1000 KBAcceptedScore: 0

Subtask #1 Testcase #1029.301 ms32 MB + 132 KBAcceptedScore: 0

Subtask #1 Testcase #1129.366 ms32 MB + 172 KBAcceptedScore: 0

Subtask #1 Testcase #1245.506 ms33 MB + 304 KBAcceptedScore: 0

Subtask #1 Testcase #1344.351 ms33 MB + 272 KBAcceptedScore: 0

Subtask #1 Testcase #1442.043 ms33 MB + 4 KBAcceptedScore: 0

Subtask #1 Testcase #1541.68 ms33 MB + 20 KBAcceptedScore: 0

Subtask #1 Testcase #1645.502 ms33 MB + 304 KBAcceptedScore: 0

Subtask #1 Testcase #1745.763 ms33 MB + 304 KBAcceptedScore: 0

Subtask #1 Testcase #1846.367 ms33 MB + 304 KBAcceptedScore: 0


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