万能头和什么的

· · 个人记录

万能头

#include<bits/stdc++.h>
namespace Fread  { const int SIZE = (1 << 18); char buf[SIZE], *p1 = buf, *p2 = buf; inline char getchar() {return (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, SIZE, stdin), p1 == p2) ? EOF : *p1++);} }
namespace Fwrite { const int SIZE = (1 << 18); char buf[SIZE], *S = buf, *T = buf+SIZE; inline void flush(){ fwrite(buf, 1, S-buf, stdout), S = buf; }  struct NTR{ ~NTR() { flush(); } }ztr;inline void putchar(char c){ *S++ = c; if(S == T) flush(); } }
#ifdef ONLINE_JUDGE
    #define getchar Fread::getchar
    #define putchar Fwrite::putchar
#endif
namespace Fastio{
    struct Reader{ template <typename T> Reader & operator >> (T & x) {char c = getchar(); bool f = false;while (c < '0' or c > '9') { if (c == '-') f = true;c = getchar();} x = 0;while(c >= '0' and c <= '9'){x = (x<<1)+(x<<3)+(c^48);c = getchar();} if (f) x = -x;return *this;}Reader&operator>>(char&c){ c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();return *this;}Reader&operator>>(char*str){ int len=0;char c=getchar(); while(c=='\n'||c==' '||c=='\r')c=getchar(); while(c!='\n'&&c!=' '&&c!='\r')str[len++]=c,c=getchar(); str[len]='\0'; return *this;}Reader & operator >> (float & x) {char c=getchar();short f=1,s=0;x=0;double t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader & operator >> (double & x) {char c=getchar();short f=1,s=0;x=0;double t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(long double&x){char c=getchar();short f=1,s=0;x=0;long double t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(__float128&x){char c=getchar();short f=1,s=0;x=0;__float128 t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.') c = getchar();else return x*=f, *this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return *this;}Reader(){}}cin;
    struct Writer{ template <typename T> Writer & operator << (T   x) {if(x == 0) return putchar('0'), *this;if(x < 0) putchar('-'), x = -x;static int sta[60], top = 0; while (x)  sta[++top] = x %10, x /= 10; while (top)  putchar(sta[top] + '0'), --top; return *this;} Writer&operator<<(char c){putchar(c);return*this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return *this;} typedef unsigned long long mxdouble; int precision = 6; Writer set_precision(int val) { precision = val; return *this; }template <typename T> T deal_precision(T x) {__float128 tmp = x;for(int i=0;i<=precision;i++)tmp*=10;tmp+=5;for(int i=0;i<=precision;i++) tmp/=10;return (T)tmp;}Writer&operator<<(float x){if(x<0)putchar('-'),x=-x; x=deal_precision(x); mxdouble _=x;x-=(__float128)_;static int sta[60];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;if(precision==0)return*this;putchar('.');for(int i=0;i<=precision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<precision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}Writer&operator<<(double x){if(x<0)putchar('-'),x=-x; x = deal_precision(x); mxdouble _=x;x-=(double)_;static int sta[60];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;if(precision==0)return*this;putchar('.');for(int i=0;i<precision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<precision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}Writer&operator<<(long double x){if(x<0)putchar('-'),x=-x; x = deal_precision(x); mxdouble _=x;x-=(__float128)_;static int sta[60];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;if(precision==0)return*this;putchar('.');for(int i=0;i<precision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<precision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}Writer&operator<<(__float128 x){if(x<0)putchar('-'),x=-x; x = deal_precision(x); mxdouble _=x;x-=(__float128)_;static int sta[60];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;if(precision==0)return*this;putchar('.');for(int i=0;i<precision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<precision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}Writer(){}}cout;
}   const char * endl = "\n"; const char * space = " ";
#define cin  Fastio :: cin
#define cout Fastio :: cout
typedef long long ll;

something with name Aster

#define Aster(_source) for (register int i = head[_source]; i; i = e[i].next)
#define v e[i].to
#define dis e[i].dis
int head[MXIM], mlc;
struct edge{
    int to, next, ds;
}e[MXIM<<1];
inline void adde(int f, int t, int ds) {
    e[++mlc].to = t;
    e[mlc].next = head[f];
    e[mlc].ds = ds;
    head[f] = mlc;
}

FastMod

typedef long long ll; typedef __int128 lll;
struct FastMod { 
    int m; ll b; 
    void init(int _m) { m = _m; b = ((lll)1<<64) / m; } 
    int operator() (ll a) {
        ll q = ((lll)a * b) >> 64; 
        a -= q * m; 
        if (a >= m) a -= m; 
        return a; 
    } 
} Mod;
int add(int a, int b) { return (a += b) >= mod ? a - mod : a; }
int mul(int a, int b) { return Mod(1ll * a * b); } 
template <typename ...Args> 
int mul(int a, Args ...b) { return mul(a, mul(b...)); }
typedef long long ll; typedef __int128 lll;
struct FastMod { int m; ll b; void init(int _m) { m = _m; b = ((lll)1<<64) / m; } int operator() (ll a) {ll q = ((lll)a * b) >> 64; a -= q * m; if (a >= m) a -= m; return a; } } Mod;
int add(int a, int b) { return (a += b) >= mod ? a - mod : a; } int mul(int a, int b) { return Mod(1ll * a * b); } template <typename ...Args> int mul(int a, Args ...b) { return mul(a, mul(b...)); }
x \mod p = x - \lfloor \frac xp \rfloor p \large \lfloor \frac{x\times \lfloor \frac {2^{64}} m \rfloor}{2^{64}} \rfloor = \lfloor \frac{\lfloor \frac {2^{64}} m \rfloor}{\frac {2^{64}} {x}} \rfloor = \lfloor \frac {2^{64}} {m\frac {2^{64}} {x}} \rfloor = \lfloor \frac {1} {m\frac {1} {x}} \rfloor = \lfloor \frac {x} {m} \rfloor

取 b = \frac {2^{64}} m,除法可以通过右移完成。

namespace

namespace joke3579 {
// 返回值快读
    template <typename __T>
    inline __T r() { 
        __T ans = 0; char ch = getchar(); bool sgn = true;
        while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
        if (ch == '-') sgn = false, ch = getchar();
        while (ch >='0' && ch <='9') ans = (ans<<1) + (ans<<3) + (ch^48), ch = getchar();
        return sgn? ans : -ans;
    }
// 指定地点快读
    template <typename __T>
    inline void get(__T & dest) { 
        dest = 0; char ch = getchar(); bool sgn = false;
        while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
        if (ch == '-') sgn = true, ch = getchar();
        while (ch >='0' && ch <='9') dest = (dest<<1) + (dest<<3) + (ch^48), ch = getchar();
        if (sgn) dest = -dest;
    }
// 闲来无事写个字符串快读 
    inline void getStr(char * dest, const char endAt) { 
        while (*(dest-1) != endAt) *dest++ = getchar();
        *--dest = '\0';
    }
// 扩欧
    template <typename __T>
    inline __T exgcd(__T a, __T b, __T &n, __T &m) { 
        if (b == 0) {
            n = 1, m = 0;
            return a;
        }
        int nowgcd = exgcd(b, a %b, m, n);
        m -= (a/b)* n;
        return nowgcd;
    }
// 线性同余方程
    template <typename __T>
    inline bool lion(__T a, __T b, __T c, __T &n, __T &m) { 
        int nowgcd = exgcd(a,b,n,m);
        if (c % nowgcd != 0) return false;
        int tmp = c / nowgcd;
        n *= tmp;
        m *= tmp;
        return true;
    }
// 线性算欧拉函数
    template <typename __T>
    inline void calcPhi(int *phi, int max) { 
        int prime[max+2], num = 0;
        bool isPrime[max+2];
        memset(prime, 0, sizeof prime);
        memset(isPrime, true, sizeof prime);
        phi[1] = 1;
        for (int i = 2; i <= max; i++) {
            if (isPrime[i]) {
                prime[num++] = i;
                phi[i] = i-1;
            } for (int j = 0; j <= num; j++) {
                int tmp = i * prime[j];
                if (tmp > max) break;
                isPrime[tmp] = false;
                if (i % prime[j] == 0) {
                    phi[tmp] = prime[j] * phi[i];
                    break;
                } else {
                    phi[tmp] = (prime[j]-1) * phi[i];
                }
            }
        }
    }
// 单个欧拉函数
    template <typename __T>
    inline __T eulerPhi(__T n) {
        __T m = __T(sqrt(n + 0.5));
        __T ans = n;
        for (int i = 2; i <= m; i++) {
            if (n % i == 0) {
                ans = ans / i * (i - 1);
                while (n % i == 0) n /= i;
            }
        } if (n != 1) ans = ans / n * (n - 1);
        return ans;
    }
// 快速幂
    template <typename __T>
    inline __T qp(__T a, __T b, __T mod) {
        __T ans = 1;
        while (b) {
            if (b & 1) ans = (ans %mod) * (a %mod) % mod;
            a = (a %mod) * (a %mod) % mod;
            b >>= 1;
        }
        return ans;
    }
// 线性算逆元
    template <typename __T>
    inline void calcInv(__T * inv, __T max, __T mod) { 
        inv[1] = 1;
        for (int i = 2; i <= max; i++) 
            inv[i] = 1ll*(mod - mod/i) * inv[mod % i] % mod;
    }
// 费马小定理算逆元
    template <typename __T>
   inline __T fermatInv(__T n, __T prime) {
       return qp(n, prime-2, prime);
   }
// 欧拉定理算逆元
   template <typename __T>
   inline __T eulerInv(__T n, __T m) {
       if (gcd(n,m) != 1) return 0;
       return qp(n, eulerPhi(m)-1, m);
   }
// BKDR Hash
    inline hashint calcHash(char * s) {
        register hashint hash = 0;
        while (hashint now = (hashint)*str++) 
            hash = hash* 131 + now;
        return hash;
    }
// KMP板子
    template <typename __T>
    inline void kmp(const char * text, int * nxt) {
        int len = strlen(text);
        nxt[0] = 0;
        for (int i = 1; i < len; i++) {
            int j = nxt[i-1];
            while (j > 0 and a[j] != a[i]) j = nxt[j-1];
            if (a[j] == a[i]) j++;
            nxt[i] = j;
        }
    }
// 小玩意
    template <typename __T> inline __T gcd(__T a, __T b) { return a % b == 0 ? b : gcd(b, a %b); }
    template <typename __T> inline __T lcm(__T a, __T b) { return a / gcd(a,b) * b; }
    template <typename __T> inline __T abs(__T a) { return a > 0 ? a : -a; }
}