_bzoj1031 [JSOI2007] character encryption cipher "suffix array"

Source: Internet
Author: User

Portal: http://www.lydsy.com/JudgeOnline/problem.php?id=1031

Save the suffix array template.

In fact, if the data range is smaller, or the space limit is a little larger, or even as long as the alphabet is a little bit more can use the suffix automaton, but unfortunately the space is not allowed, just use the suffix array!

In fact, I still do not understand the code, whether it should be a black box code back down?

#include <cstdio> #include <cstring> #include <algorithm>const int maxn = 200005;int N, mx, SA[MAXN], t1[ MAXN], T2[MAXN], C[MAXN], *x, *y;char s[maxn];int main (void) {scanf ("%s", s), n = strlen (s); memcpy (s + N, S, n-1); n = (n << 1)-1;x = T1;y = T2;mx = 128;memset (c, 0, sizeof c); for (int i = 0; i < n; ++i) {++c[x[i] = s[i];} for (int i = 1; i < mx; ++i) {C[i] + = c[i-1];} for (int i = n-1; ~i; i.) {sa[--c[x[i]]] = i;} int p;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;}} memset (c, 0, sizeof c); for (int i = 0; i < n; ++i) {++c[x[y[i]];} for (int i = 0; i < mx; ++i) {C[i] + = c[i-1];} for (int i = n-1; ~i; i.) {SA[--C[X[Y[I]]] [= Y[i];}  Std::swap (x, y);p = 1;x[sa[0]] = 0;for (int i = 1; i < n; ++i) {x[sa[i]] = y[sa[i-1] [= Y[sa[i]] && y[sa[i- 1] + K] = = Y[sa[i] + K]? P-1: p++;} if (P >= N) {break;} mx = p;} Int TEM = (n + 1) >> 1;for (int i = 0; i < n; ++i) {if (Sa[i] < tem) {printf ("%c", S[sa[i] + tem-1]);}} return 0;}

  

_bzoj1031 [JSOI2007] character encryption cipher "suffix array"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.