hiho week 128 register

Ended

Participants:146

Verdict:Accepted
Score:100 / 100
Submitted:2016-12-14 18:11:12

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>
#define rg register
#define rep(i,x,y) for(rg int i=(x);i<=(y);++i)
#define per(i,x,y) for(rg int i=(x);i>=(y);--i)
using namespace std;
typedef long long LL;
const int N=1e6+10,P=N<<1,alp=26;
inline bool vaild(char c){return c>='a'&&c<='z';}
inline char gc(){char c=getchar();while(!vaild(c))c=getchar();return c;}
int n,s[N];
struct SAM{
    int son[P][alp],pr[P],step[P],tot,last;
    SAM(){last=tot=1;}
    void ins(int c,int l){
        int k=++tot;step[k]=l;
        while(last&&son[last][c]==0)son[last][c]=k,last=pr[last];
        if(last){
            int q=son[last][c];
            if(step[q]==step[last]+1)pr[k]=q;
            else{
                int nq=++tot;
                step[nq]=step[last]+1;
                memcpy(son[nq],son[q],sizeof(son[q]));
                pr[nq]=pr[q];
                pr[q]=pr[k]=nq;
                while(last&&son[last][c]==q)son[last][c]=nq,last=pr[last];
            }
        }else pr[k]=1;
        last=k;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX