关于fread快读
  • 板块学术版
  • 楼主xxxxxxxb
  • 当前回复4
  • 已保存回复4
  • 发布时间2023/9/2 13:26
  • 上次更新2023/11/2 23:55:08
查看原帖
关于fread快读
800703
xxxxxxxb楼主2023/9/2 13:26

rt,这东西在OI中用处大吗

namespace IO {
    #define ll long long
    const int MAX = 1<<23;
    char buf[MAX],*p1=buf,*p2=buf;
    char obuf[MAX],*o=obuf;
    #define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
    template<typename T>
    inline T read() {
        T res = 0;
        int f = 1;
        char c = gc();
        while(!isdigit(c)) {
            if(c=='-') f=-1;
            c=gc();
        }
        while(isdigit(c)) {
            res = (res<<3)+(res<<1)+(c^48);
            c=gc();
        }
        return res*f;
    }
    void print(ll x) {
        if(x > 9) print(x/10);
        *o++=(x%10)+'0';
    }
    void pc(char c) {
        *o++=c;
    }
    void write(ll x,char end) {
        if(x<0) pc('-');
        print(abs(x));
        pc(end);
    }
    void flush() {
        fwrite(obuf,o-obuf,1,stdout);
        o = obuf;
    }
    #undef ll
}

还有就是为什么有时候用了template的快读会TLE

2023/9/2 13:26
加载中...