hiho week 131 register

Ended

Participants:147

Verdict:Accepted
Score:100 / 100
Submitted:2017-01-02 14:44:05

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;
const int N=1e5+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;}
inline void dn(int&x,int y){if(y<x)x=y;}
int cas,s[N],t[N<<1],n;
struct SAM{
    int tot,step[P],son[P][alp],pr[P],mark[P],num[P];
    SAM(){tot=1;}
    int ins(int c,int p){
        int k=++tot;step[k]=step[p]+1;num[k]=1;
        while(p&&son[p][c]==0)son[p][c]=k,p=pr[p];
        if(p){
            int q=son[p][c];
            if(step[q]==step[p]+1)pr[k]=q;
            else{
                int nq=++tot;step[nq]=step[p]+1;
                memcpy(son[nq],son[q],sizeof(son[q]));
                pr[nq]=pr[q];pr[q]=pr[k]=nq;
                while(p&&son[p][c]==q)son[p][c]=nq,p=pr[p];
            }
        }else pr[k]=1;
        return k;
    }
    int q[P],c[P];
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX