# bzoj1031 [JSOI2007]字符加密Cipher

### Description

JSOI07 SOI07J OI07JS I07JSO 07JSOI 7JSOI0

07JSOI 7JSOI0 I07JSO JSOI07 OI07JS SOI07J

I0O7SJ

### Sample Input

JSOI07


### Sample Output

I0O7SJ


### Solution

#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;

#define N 200001
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define drp(i, a, b) for (int i = a; i >= b; i--)
#define ll long long

int x = 0, flag = 1; char ch = getchar(); while (!isdigit(ch)) { if (!(ch ^ '-')) flag = -1; ch = getchar(); }
while (isdigit(ch)) x = (x << 1) + (x << 3) + ch - '0', ch = getchar(); return x * flag;
}

int n;
char in[N]; int s[N];
int sa[N], t1[N], t2[N], c[N], rk[N], height[N];

void get_sa() {
int *x = t1, *y = t2, m = 54;
rep(i, 1, n) c[x[i] = s[i]]++;
rep(i, 1, m) c[i] += c[i - 1];
drp(i, n, 1) sa[c[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;
memset(c, 0, sizeof(c));
rep(i, 1, n) c[x[i]]++;
rep(i, 1, m) c[i] += c[i - 1];
drp(i, n, 1) sa[c[x[y[i]]]--] = y[i];
swap(x, y), p = 0, x[sa[1]] = ++p;
rep(i, 2, n) x[sa[i]] = y[sa[i - 1]] == y[sa[i]] && y[sa[i - 1] + k] == y[sa[i] + k] ? p : ++p;
if ((m = p) == n) break;
}
}

void get_height() {
rep(i, 1, n) rk[sa[i]] = i;
int k = 0;
rep(i, 1, n) {
if (k) k--;
int p = sa[rk[i] - 1];
while (s[i + k] == s[p + k]) k++;
height[rk[i]] = k;
}
}

int main() {
scanf("%s", in + 1); n = strlen(in + 1);
rep(i, 1, n) in[i + n] = in[i], s[n + i] = s[i] = (in[i] >= 'a' && in[i] <= 'z') ? in[i] - 'a' + 1 : in[i] - 'A' + 1 + 26;
n += n; get_sa();
rep(i, 1, n) if (sa[i] <= n / 2) printf("%c", in[sa[i] + n / 2 - 1]);
return 0;
}

posted @ 2018-02-19 16:35  aziint  阅读(141)  评论(0编辑  收藏  举报