diff --git a/LibreOJ/111/111.cpp b/LibreOJ/111/111.cpp new file mode 100644 index 00000000..7c46dc10 --- /dev/null +++ b/LibreOJ/111/111.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e6 + 5; + +int n; +std::string s; +std::array sa; +std::array 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; +} diff --git a/LibreOJ/111/data/1.in b/LibreOJ/111/data/1.in new file mode 100644 index 00000000..4ce3ee88 --- /dev/null +++ b/LibreOJ/111/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ac2d31f07d9d5c4f7a6efa45a9b7f14aa3f1063a9bf0e4d08d5106dc141c0781 +size 100 diff --git a/LibreOJ/111/data/1.out b/LibreOJ/111/data/1.out new file mode 100644 index 00000000..7799084d --- /dev/null +++ b/LibreOJ/111/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0a9cebb755942ae24a49f051e9999793085c042ca761c2b564dca7653199bc68 +size 292 diff --git a/LibreOJ/111/data/10.in b/LibreOJ/111/data/10.in new file mode 100644 index 00000000..6531e299 --- /dev/null +++ b/LibreOJ/111/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:42349427672294ce2f9f961971c69809975b31185a37c8b9aa0e59940bfafeb5 +size 1000000 diff --git a/LibreOJ/111/data/10.out b/LibreOJ/111/data/10.out new file mode 100644 index 00000000..879fe7b7 --- /dev/null +++ b/LibreOJ/111/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ab2eece2e70b7a5f36497d4a6c3768de38b65d08ba2463240072856ed8a9d497 +size 6888896 diff --git a/LibreOJ/111/data/11.in b/LibreOJ/111/data/11.in new file mode 100644 index 00000000..8f5c3c10 --- /dev/null +++ b/LibreOJ/111/data/11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b3e48c9ec42fd921896d13294fc5fc91a038eba8bc6a3fcd92f82ed22efae8ee +size 1000002 diff --git a/LibreOJ/111/data/11.out b/LibreOJ/111/data/11.out new file mode 100644 index 00000000..be68b971 --- /dev/null +++ b/LibreOJ/111/data/11.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2c6d8ee7855e380870b8ae5141670945339eee3665edd979960bb888304cce5e +size 6888897 diff --git a/LibreOJ/111/data/2.in b/LibreOJ/111/data/2.in new file mode 100644 index 00000000..85c6ad6e --- /dev/null +++ b/LibreOJ/111/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:87631c4225bf4b4cbc01e443b72c0dfea98ab481ab0972509261301d86f9a581 +size 1000 diff --git a/LibreOJ/111/data/2.out b/LibreOJ/111/data/2.out new file mode 100644 index 00000000..fc0b8987 --- /dev/null +++ b/LibreOJ/111/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:932b451c0175a69df2b2ff37db10289775902bbc272b27230a66593f040ea16d +size 3893 diff --git a/LibreOJ/111/data/3.in b/LibreOJ/111/data/3.in new file mode 100644 index 00000000..85c6ad6e --- /dev/null +++ b/LibreOJ/111/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:87631c4225bf4b4cbc01e443b72c0dfea98ab481ab0972509261301d86f9a581 +size 1000 diff --git a/LibreOJ/111/data/3.out b/LibreOJ/111/data/3.out new file mode 100644 index 00000000..fc0b8987 --- /dev/null +++ b/LibreOJ/111/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:932b451c0175a69df2b2ff37db10289775902bbc272b27230a66593f040ea16d +size 3893 diff --git a/LibreOJ/111/data/4.in b/LibreOJ/111/data/4.in new file mode 100644 index 00000000..83c441dc --- /dev/null +++ b/LibreOJ/111/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8dff6cde0c749c1178fcdae3b649b39100e3fe488d197eab9d8f11791ef880bb +size 10000 diff --git a/LibreOJ/111/data/4.out b/LibreOJ/111/data/4.out new file mode 100644 index 00000000..ecdaf0bb --- /dev/null +++ b/LibreOJ/111/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:84b8f114292e31c0e6274e66c72cc8cf3e034d0e42b6473ebfd82513be2c0f94 +size 48894 diff --git a/LibreOJ/111/data/5.in b/LibreOJ/111/data/5.in new file mode 100644 index 00000000..83c441dc --- /dev/null +++ b/LibreOJ/111/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8dff6cde0c749c1178fcdae3b649b39100e3fe488d197eab9d8f11791ef880bb +size 10000 diff --git a/LibreOJ/111/data/5.out b/LibreOJ/111/data/5.out new file mode 100644 index 00000000..ecdaf0bb --- /dev/null +++ b/LibreOJ/111/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:84b8f114292e31c0e6274e66c72cc8cf3e034d0e42b6473ebfd82513be2c0f94 +size 48894 diff --git a/LibreOJ/111/data/6.in b/LibreOJ/111/data/6.in new file mode 100644 index 00000000..bc33742c --- /dev/null +++ b/LibreOJ/111/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:32deb606c598ebfd7ad0989d5ed14fd12daf1765feed78d08fd08322f5cdb089 +size 100000 diff --git a/LibreOJ/111/data/6.out b/LibreOJ/111/data/6.out new file mode 100644 index 00000000..99d202a4 --- /dev/null +++ b/LibreOJ/111/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d5485e378abfeb76db93b9baa62ae926be5e2bdd08745080ed684166e37b9c59 +size 588895 diff --git a/LibreOJ/111/data/7.in b/LibreOJ/111/data/7.in new file mode 100644 index 00000000..bc33742c --- /dev/null +++ b/LibreOJ/111/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:32deb606c598ebfd7ad0989d5ed14fd12daf1765feed78d08fd08322f5cdb089 +size 100000 diff --git a/LibreOJ/111/data/7.out b/LibreOJ/111/data/7.out new file mode 100644 index 00000000..99d202a4 --- /dev/null +++ b/LibreOJ/111/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d5485e378abfeb76db93b9baa62ae926be5e2bdd08745080ed684166e37b9c59 +size 588895 diff --git a/LibreOJ/111/data/8.in b/LibreOJ/111/data/8.in new file mode 100644 index 00000000..d44cc52f --- /dev/null +++ b/LibreOJ/111/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:401e4734502a780deed40c90e57cc0e5c48c7e2a49ecf64282d5b3a2b5ade869 +size 1000000 diff --git a/LibreOJ/111/data/8.out b/LibreOJ/111/data/8.out new file mode 100644 index 00000000..0252c7bf --- /dev/null +++ b/LibreOJ/111/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9244d48815d5f3b9c400d10a05b33e5ca9cf8399910a524133a64ae95efea346 +size 6888896 diff --git a/LibreOJ/111/data/9.in b/LibreOJ/111/data/9.in new file mode 100644 index 00000000..77e793b1 --- /dev/null +++ b/LibreOJ/111/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:913175b2cd0188062baa35a4d86710bebd352466c294c7c9f7acd3a908455daa +size 1000000 diff --git a/LibreOJ/111/data/9.out b/LibreOJ/111/data/9.out new file mode 100644 index 00000000..72af4b16 --- /dev/null +++ b/LibreOJ/111/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea0792a5f4e54d71ff8c9349a3f243d882f7d922966d0fe8eaaed3d362557e99 +size 6888896