limingx的一些板子

· · 算法·理论

KMP next

for(int i=1;i<p.size();i++){
    while(j>0&&p[i]!=p[j])j=next[j-1];
    if(p[i]==p[j])j++;
    next[i]=j;
}

快读

inline int read(){
    int x=0,f=1;
    char ch=getchar_unlocked();
    while(!isdigit(ch)){
        if(ch=='-') f=-1;
        ch=getchar_unlocked();
    }
    while(isdigit(ch)){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar_unlocked();
    }
    return x*f;
}

快写

inline void write(int x) {
    if(x<0){
        putchar('-');
        x=-x;
    }
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

重载