其他分享
首页 > 其他分享> > 卡常技巧

卡常技巧

作者:互联网

普通快读快写:

long long rd(){char ch=getchar();long long x=0,f=1;while(ch<'0' || ch>'9'){if(ch=='-') f=-1;ch=getchar();}
                        while('0'<=ch && ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
void wr(long long x){if(x<0){putchar('-');x=-x;}if(x>9) wr(x/10);putchar(x%10+'0');}

fread()/fwrite():

namespace IO
{
    FILE *input(stdin), *output(stdout);
    class qistream
    {
        static const size_t SIZE = 1 << 12, BLOCK = 32;
        FILE *fp;
        char buf[SIZE];
        int p;

    public:
        qistream(FILE *_fp = stdin) : fp(_fp), p(0) { fread(buf + p, 1, SIZE - p, fp); }
        inline void flush() { memmove(buf, buf + p, SIZE - p), fread(buf + SIZE - p, 1, p, fp), p = 0; }
        template <class T>
        qistream &operator>>(T &x)
        {
            x = 0, p + BLOCK >= SIZE ? flush() : void();
            bool flag = false;
            for (; !isdigit(buf[p]); ++p)
                flag = buf[p] == '-';
            for (; isdigit(buf[p]); ++p)
                x = x * 10 + buf[p] - '0';
            x = flag ? -x : x;
            return *this;
        }
        inline char getch() { return buf[p++]; }
    } qcin(input);
    class qostream
    {
        static const size_t SIZE = 1 << 12, BLOCK = 32;
        FILE *fp;
        char buf[SIZE];
        int p;

    public:
        qostream(FILE *_fp = stdout) : fp(_fp), p(0) {}
        ~qostream() { fwrite(buf, 1, p, fp); }
        inline void flush() { fwrite(buf, 1, p, fp), p = 0; }
        template <class T>
        qostream &operator<<(T x)
        {
            int len = 0;
            p + BLOCK >= SIZE ? flush() : void(), x < 0 ? (x = -x, buf[p++] = '-') : 0;
            do
                buf[p + len] = x % 10 + '0', x /= 10, ++len;
            while (x);
            for (int i = 0, j = len - 1; i < j; ++i, --j)
                swap(buf[p + i], buf[p + j]);
            p += len;
            return *this;
        }
        inline void putch(char ch) { buf[p++] = ch; }
    } qcout(output);
}
using namespace IO;

 

火车头:

 1 #pragma GCC optimize(2)
 2 #pragma GCC optimize(3)
 3 #pragma GCC target("avx")
 4 #pragma GCC optimize("Ofast")
 5 #pragma GCC optimize("inline")
 6 #pragma GCC optimize("-fgcse")
 7 #pragma GCC optimize("-fgcse-lm")
 8 #pragma GCC optimize("-fipa-sra")
 9 #pragma GCC optimize("-ftree-pre")
10 #pragma GCC optimize("-ftree-vrp")
11 #pragma GCC optimize("-fpeephole2")
12 #pragma GCC optimize("-ffast-math")
13 #pragma GCC optimize("-fsched-spec")
14 #pragma GCC optimize("unroll-loops")
15 #pragma GCC optimize("-falign-jumps")
16 #pragma GCC optimize("-falign-loops")
17 #pragma GCC optimize("-falign-labels")
18 #pragma GCC optimize("-fdevirtualize")
19 #pragma GCC optimize("-fcaller-saves")
20 #pragma GCC optimize("-fcrossjumping")
21 #pragma GCC optimize("-fthread-jumps")
22 #pragma GCC optimize("-funroll-loops")
23 #pragma GCC optimize("-fwhole-program")
24 #pragma GCC optimize("-freorder-blocks")
25 #pragma GCC optimize("-fschedule-insns")
26 #pragma GCC optimize("inline-functions")
27 #pragma GCC optimize("-ftree-tail-merge")
28 #pragma GCC optimize("-fschedule-insns2")
29 #pragma GCC optimize("-fstrict-aliasing")
30 #pragma GCC optimize("-fstrict-overflow")
31 #pragma GCC optimize("-falign-functions")
32 #pragma GCC optimize("-fcse-skip-blocks")
33 #pragma GCC optimize("-fcse-follow-jumps")
34 #pragma GCC optimize("-fsched-interblock")
35 #pragma GCC optimize("-fpartial-inlining")
36 #pragma GCC optimize("no-stack-protector")
37 #pragma GCC optimize("-freorder-functions")
38 #pragma GCC optimize("-findirect-inlining")
39 #pragma GCC optimize("-frerun-cse-after-loop")
40 #pragma GCC optimize("inline-small-functions")
41 #pragma GCC optimize("-finline-small-functions")
42 #pragma GCC optimize("-ftree-switch-conversion")
43 #pragma GCC optimize("-foptimize-sibling-calls")
44 #pragma GCC optimize("-fexpensive-optimizations")
45 #pragma GCC optimize("-funsafe-loop-optimizations")
46 #pragma GCC optimize("-fdelete-null-pointer-checks")

 

标签:GCC,ch,技巧,++,pragma,卡常,buf,optimize
来源: https://www.cnblogs.com/Gokix/p/ka-chang-ji-qiao.html