Advertisement
Guest User

Untitled

a guest
Nov 28th, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define mp make_pair
  4. #define pb push_back
  5. typedef long long ll;
  6. typedef pair<int,int> pii;
  7. #define X first
  8. #define Y second
  9.  
  10.  
  11.  
  12. int n, l, j, old_a[MAXN], new_a[MAXN], old_color[MAXN], new_color[MAXN];
  13. int cnt[MAXN], h[MAXN];
  14. int *a, *b, *clr_a, *clr_b;
  15.  
  16. void create_sa(string s)
  17. {
  18.  
  19.     a = &old_a[0];
  20.     b = &new_a[0];
  21.     clr_a = &old_color[0];
  22.     clr_b = &new_color[0];
  23.    
  24.     forn(i, n)
  25.         a[i] = s[i];
  26.  
  27.     forn(i, MAXN)
  28.         cnt[i] = 0;
  29.     forn(i, n) {
  30.         cnt[a[i]]++;
  31.         clr_a[i] = a[i];
  32.     }
  33.     h[0] = 0;
  34.     forab(i, 1, MAXN)
  35.         h[i] = h[i - 1] + cnt[i - 1];
  36.     forn(i, n)
  37.         a[h[clr_a[i]]++] = i;
  38.  
  39.     h[0] = 0;
  40.     forab(i, 1, MAXN)
  41.         h[i] = h[i - 1] + cnt[i - 1];
  42.  
  43.     l = 1;
  44.     while (l < n) {
  45.         forn(i, n) {
  46.             j = (2 * n + a[i] - l) % n;
  47.             b[h[clr_a[j]]] = j;
  48.             h[clr_a[j]]++;
  49.         }
  50.         clr_b[b[0]] = 0;
  51.         h[0] = 0;
  52.         forab(i, 1, n) {
  53.             if (clr_a[b[i]] == clr_a[b[i - 1]] && clr_a[(b[i] + l) % n] == clr_a[(b[i - 1] + l) % n])
  54.                 clr_b[b[i]] = clr_b[b[i - 1]];
  55.             else {
  56.                 clr_b[b[i]] = clr_b[b[i - 1]] + 1;
  57.                 h[clr_b[b[i]]] = i;
  58.             }
  59.         }
  60.  
  61.         swap(a, b);
  62.         swap(clr_a, clr_b);
  63.         l <<= 1;
  64.     }
  65. }
  66.  
  67. int main()
  68. {
  69.    
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement