hiho week 120 register

Ended

Participants:410

Verdict:Accepted
Score:100 / 100
Submitted:2016-10-17 20:50:56

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 100010;
int rk[maxn],sa[maxn],height[maxn],rp;
int c[maxn],t[maxn],t2[maxn],s[maxn],n;
void build_sa(int m) {
    int i,j,*x = t,*y = t2;
    for(i = 0; i < m; ++i) c[i] = 0;
    for(i = 0; i < n; ++i) c[x[i] = s[i]]++;
    for(i = 1; i < m; ++i) c[i] += c[i-1];
    for(i = n-1; i >= 0; --i) sa[--c[x[i]]] = i;
    for(int k = 1; k <= n; k <<= 1) {
        int p = 0;
        for(i = n-k; i < n; ++i) y[p++] = i;
        for(i = 0; i < n; ++i)
            if(sa[i] >= k) y[p++] = sa[i] - k;
        for(i = 0; i < m; ++i) c[i] = 0;
        for(i = 0; i < n; ++i) c[x[y[i]]]++;
        for(i = 1; i < m; ++i) c[i] += c[i-1];
        for(i = n-1; i >= 0; --i) sa[--c[x[y[i]]]] = y[i];
        swap(x,y);
        p = 1;
        x[sa[0]] = 0;
        for(i = 1; i < n; ++i)
            if(y[sa[i]] == y[sa[i-1]] && y[sa[i]+k] == y[sa[i-1]+k])
                x[sa[i]] = p-1;
            else x[sa[i]] = p++;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX