提交记录 9128


用户 题目 状态 得分 用时 内存 语言 代码长度
Timsei 1006. 【模板题】后缀排序 Accepted 100 45.818 ms 3536 KB C++ 1.35 KB
提交时间 评测时间
2019-04-12 16:42:57 2020-08-01 01:32:45
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 5;

#define REP(i, a, b) for(int i = (a); i <= (b); ++ i)
#define PER(i, a, b) for(int i = (a); i >= (b); -- i)

int n;
char s[N];

namespace SA {
  int Mem[N * 10], sa[N], H[N], rk[N];
  
  void build(int m) {
    int *x = Mem, *y = Mem + (N << 1), *z = y + (N << 1);
    REP(i, 1, m) z[i] = 0;
    REP(i, 1, n) ++ z[x[i] = s[i]];
    REP(i, 1, m) z[i] += z[i - 1];
    REP(i, 1, n) sa[z[x[i]] --] = i;
    for(int k = 1; k <= n; k <<= 1) {
      int p = 0;
      REP(i, n - k + 1, n) y[++ p] = i;
      REP(i, 1, n) if(sa[i] > k) y[++ p] = sa[i] - k;
      REP(i, 1, m) z[i] = 0;
      REP(i, 1, n) ++ z[x[i]];
      REP(i, 1, m) z[i] += z[i - 1];
      PER(i, n, 1) sa[z[x[y[i]]] --] = y[i];
      swap(x, y); p = 0;
      REP(i, 1, n) x[sa[i]] = (y[sa[i]] == y[sa[i - 1]] && y[sa[i] + k] == y[sa[i - 1] + k]) ? p : ++ p;
      if(p == n) break;
      m = p;
    }
  }

  void getheight() {
    int Now = 0;
    REP(i, 1, n) rk[sa[i]] = i;
    REP(i, 1, n) {
      if(Now) -- Now;
      if(rk[i] == n) continue;
      while(s[i + Now] == s[sa[rk[i] + 1] + Now]) ++ Now;
      H[rk[i]] = Now;
    }
  }
}

int main() {
  scanf("%s", s + 1); n = strlen(s + 1);
  SA :: build('z');
  SA :: getheight();
  REP(i, 1, n) printf("%d ", SA :: sa[i]); puts("");
  REP(i, 1, n - 1) printf("%d ", SA :: H[i]); puts("");
}


CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #136.72 us60 KBAcceptedScore: 0

Subtask #1 Testcase #245.31 us64 KBAcceptedScore: 0

Subtask #1 Testcase #344.43 us64 KBAcceptedScore: 100

Subtask #1 Testcase #443.79 us64 KBAcceptedScore: 0

Subtask #1 Testcase #542.2 us64 KBAcceptedScore: 0

Subtask #1 Testcase #641.93 us64 KBAcceptedScore: 0

Subtask #1 Testcase #730.061 ms3 MB + 160 KBAcceptedScore: 0

Subtask #1 Testcase #845.818 ms3 MB + 380 KBAcceptedScore: 0

Subtask #1 Testcase #932.111 ms3 MB + 252 KBAcceptedScore: 0

Subtask #1 Testcase #1020.819 ms2 MB + 140 KBAcceptedScore: 0

Subtask #1 Testcase #1121.492 ms2 MB + 180 KBAcceptedScore: 0

Subtask #1 Testcase #1237.027 ms3 MB + 444 KBAcceptedScore: 0

Subtask #1 Testcase #1335.915 ms3 MB + 464 KBAcceptedScore: 0

Subtask #1 Testcase #1433.369 ms3 MB + 276 KBAcceptedScore: 0

Subtask #1 Testcase #1533.021 ms3 MB + 280 KBAcceptedScore: 0

Subtask #1 Testcase #1635.709 ms3 MB + 444 KBAcceptedScore: 0

Subtask #1 Testcase #1735.632 ms3 MB + 444 KBAcceptedScore: 0

Subtask #1 Testcase #1835.902 ms3 MB + 444 KBAcceptedScore: 0


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