0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

#111. 后缀排序

https://loj.ac/s/1475176
This commit is contained in:
Baoshuo Ren 2022-06-03 21:17:37 +08:00
parent 61cdf9c0cc
commit b37e815f77
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
23 changed files with 122 additions and 0 deletions

56
LibreOJ/111/111.cpp Normal file
View File

@ -0,0 +1,56 @@
#include <iostream>
#include <algorithm>
#include <array>
#include <string>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e6 + 5;
int n;
std::string s;
std::array<int, N> sa;
std::array<int, N << 1> rk, rk1;
void get_sa() {
for (int i = 1; i <= n; i++) {
sa[i] = i;
rk[i] = s[i];
}
for (int w = 1; w < n; w <<= 1) {
std::sort(sa.begin() + 1, sa.begin() + 1 + n, [&](auto x, auto y) {
return rk[x] == rk[y] ? rk[x + w] < rk[y + w] : rk[x] < rk[y];
});
rk1 = rk;
for (int i = 1, p = 0; i <= n; i++) {
if (rk1[sa[i]] == rk1[sa[i - 1]] && rk1[sa[i] + w] == rk1[sa[i - 1] + w]) {
rk[sa[i]] = p;
} else {
rk[sa[i]] = ++p;
}
}
}
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> s;
n = s.size();
s = ' ' + s;
get_sa();
for (int i = 1; i <= n; i++) {
cout << sa[i] << ' ';
}
cout << endl;
return 0;
}

BIN
LibreOJ/111/data/1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/111/data/1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/111/data/10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/111/data/10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/111/data/11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/111/data/11.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/111/data/2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/111/data/2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/111/data/3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/111/data/3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/111/data/4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/111/data/4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/111/data/5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/111/data/5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/111/data/6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/111/data/6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/111/data/7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/111/data/7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/111/data/8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/111/data/8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/111/data/9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/111/data/9.out (Stored with Git LFS) Normal file

Binary file not shown.