读写优化
神秘优化
IOS 优化 cin cout
把这两行加到 main() 中开头处即可。
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
快读快写
贴上代码。把 read() 和 write 单独抠出来就是朴素的版本。
namespace IO {
const int bufsz = 1 << 20;
char ibuf[bufsz], *p1 = ibuf, *p2 = ibuf;
char obuf[bufsz], *p3 = obuf, stk[50];
#define getchar() (p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, bufsz, stdin), p1 == p2) ? EOF : *p1++)
#define flush() (fwrite(obuf, 1, p3 - obuf, stdout), p3 = obuf)
#define putchar(ch) (p3 == obuf + bufsz && flush(), *p3++ = (ch))
il int read() {
int x = 0; char ch = getchar(); bool t = 0;
while (ch < '0' || ch > '9') {t ^= ch == '-'; ch = getchar();}
while (ch >= '0' && ch <= '9') {x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar();}
return t ? -x : x;
}
il void write(int x, bool t = 1) {
int top = 0;
x < 0 ? putchar('-'), x = -x : 0;
do {stk[++top] = x % 10 | 48; x /= 10;} while(x);
while(top) putchar(stk[top--]);
t ? putchar('\n') : putchar(' ');
}
struct FL {~FL() {flush();}} fl;
#undef getchar()
#undef putchar()
#undef flush()
}
using IO::read;
using IO::write;
框架代码
upd at 2025.11.21
#include <bits/stdc++.h>
#define il inline
using namespace std;
bool Beg;
namespace Zctf1088 {
namespace IO {
const int bufsz = 1 << 20;
char ibuf[bufsz], *p1 = ibuf, *p2 = ibuf;
#define getchar() (p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, bufsz, stdin), p1 == p2) ? EOF : *p1++)
il int read() {
int x = 0; char ch = getchar(); bool t = 0;
while (ch < '0' || ch > '9') {t ^= ch == '-'; ch = getchar();}
while (ch >= '0' && ch <= '9') {x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar();}
return t ? -x : x;
}
char obuf[bufsz], *p3 = obuf, stk[50];
#define flush() (fwrite(obuf, 1, p3 - obuf, stdout), p3 = obuf)
#define putchar(ch) (p3 == obuf + bufsz && flush(), *p3++ = (ch))
il void write(int x, bool t = 0) {
int top = 0;
x < 0 ? putchar('-'), x = -x : 0;
do {stk[++top] = x % 10 | 48; x /= 10;} while(x);
while (top) putchar(stk[top--]);
t ? putchar(' ') : putchar('\n');
}
il void wrt() {putchar('\n');}
struct FL {
~FL() {flush();}
} fl;
}
using IO::read; using IO::write; using IO::wrt;
// something
signed main() {
// something
return 0;
}}
bool End;
il void Usd() {cerr << "\nUse: " << (&Beg - &End) / 1024.0 / 1024.0 << "MB " << (double)clock() * 1000.0 / CLOCKS_PER_SEC << "ms\n";}
signed main() {
Zctf1088::main();
Usd();
return 0;
}

浙公网安备 33010602011771号