跳到正文

个人记录

fastio&fastmod

SDSXC约 4 分钟
原文
文章信息与版本

文章信息

发布
2025年10月25日
收录
2025年12月12日
更新
2026年9月29日
篇幅
约 4 分钟

版本

  1. v1当前

fastio

C++
struct FastIO{
    static const int IOSIZE = 65536;
    char in[IOSIZE],*P,*pp,out[IOSIZE],*q,*qq,ch[20],*t,b;
    FastIO():P(in),pp(in),q(out),qq(out+IOSIZE),t(ch),b(1){}
    ~FastIO(){fwrite(out,1,q-out,stdout);}
    char getch(){ return P==pp&&(pp=(P=in)+fread(in,1,IOSIZE,stdin),P==pp)?b=0,EOF:*P++; }
    void putch(char x){ q==qq&&(fwrite(out,1,q-out,stdout),q=out),*q++=x; }
    void puts(const char str[]){fwrite(out,1,q-out,stdout),fwrite(str,1,strlen(str),stdout),q=out;}
    #define indef(T) FastIO& operator>>(T& x){\
        x=0;char f=0,ch;\
        while(!isdigit(ch=getch())&&b)f|=ch=='-';\
        while(isdigit(ch))x=x*10+(ch^48),ch=getch();\
        return x=f?-x:x,*this;\
    }
    indef(int)
    indef(long long)
    FastIO& operator>>(char& ch){return ch=getch(),*this;}
    FastIO& operator>>(char* s){
        char ch;
        while(isspace(ch=getch())&&b);
        while(!isspace(ch)&&b)*(s++)=ch,ch=getch();
        *s='\0';
        return *this;
    }
    FastIO& operator>>(string& s){
        s="";char ch;
        while(isspace(ch=getch())&&b);
        while(!isspace(ch)&&b)s+=ch,ch=getch();
        return *this;
    }
    #define outdef(_T) inline FastIO& operator<<(_T x){\
        !x&&(putch('0'),0),x<0&&(putch('-'),x=-x);\
        while(x)*t++=x%10+48,x/=10;\
        while(t!=ch)putch(*--t);\
        return *this;\
    }
    outdef(int)
    outdef(long long)
    FastIO& operator<<(char ch){return putch(ch),*this;}
    FastIO& operator<<(const char str[]){return puts(str),*this;}
    FastIO& operator<<(const string& s){return puts(s.c_str()),*this;}
    operator bool(){return b;}
}io;

fastmod

C++
struct FastMod{
	ll m;int ppp;
	void init(int pp){
    	m=((__int128)1<<63)/pp;ppp=pp;
	}
	auto operator()(ll x)->ll{return x-((__int128(x)*m)>>63)*ppp;}
} md;
ll p=1;
inline ll M(ll x){
	x=md(x);
	if(x>=p)x-=p;
	return x;
};
原文