快读快输

· · 个人记录

static char ibuf[1 << 20], *ip = ibuf, *iend = ibuf;
inline int gc() { if (ip == iend) iend = (ip = ibuf) + fread(ibuf, 1, 1 << 20, stdin); return ip == iend ? EOF : *ip++; }
const int BUFSIZE = 1 << 20;
char obuf[BUFSIZE], *op = obuf;
inline void flush() { fwrite(obuf, 1, op - obuf, stdout); op = obuf; }
inline void pc(char c) { if (op == obuf + BUFSIZE) flush(); *op++ = c; }
inline bool blank(const char x) { return x == ' ' || x == '\n' || x == '\r' || x == '\t'; }
template<typename Tp> inline void read(Tp &x) { x = 0; bool z = true; int a = gc(); for(; !('0' <= a && a <= '9'); a = gc()) if(a == '-') z = false; for(; ('0' <= a && a <= '9'); a = gc()) x = (x << 1) + (x << 3) + (a ^ 48); x = (z ? x : ~x + 1); }
inline void read(double &x) { x = 0.0; bool z = true; double y = 0.1; int a = gc(); for(; !('0' <= a && a <= '9'); a = gc()) if(a == '-') z = false; for(; ('0' <= a && a <= '9'); a = gc()) x = x * 10 + (a ^ 48); if(a != '.') return x = z ? x : -x, void(); for(a = gc(); ('0' <= a && a <= '9'); a = gc(), y /= 10) x += y * (a ^ 48); x = (z ? x : -x); }
inline void read(char &x) { for(x = gc(); blank(x) && (x ^ -1); x = gc()); }
inline void read(char *x) { char a = gc(); for(; blank(a) && (a ^ -1); a = gc()); for(; !blank(a) && (a ^ -1); a = gc()) *x++ = a; *x = 0; }
inline void read(std::string &x) { x = ""; char a = gc(); for(; blank(a) && (a ^ -1); a = gc()); for(; !blank(a) && (a ^ -1); a = gc()) x += a; }
template<typename T, typename ...Tp> inline void read(T &x, Tp &...y) { read(x), read(y...); }
template<typename Tp> inline void write(Tp x) { if(!x) return pc(48), void(); if(x < 0) pc('-'), x = ~x + 1; int len = 0; char tmp[64]; for(; x; x /= 10) tmp[++len] = x % 10 + 48; while(len) pc(tmp[len--]); }
inline void write(const double x) { int a = 6; double b = x, c = b; if(b < 0) pc('-'), b = -b, c = -c; double y = 5 * powl(10.0, -a - 1); b += y, c += y; int len = 0; char tmp[64]; if(b < 1) pc(48); else for(; b >= 1; b /= 10) tmp[++len] = std::floor(b) - std::floor(b / 10) * 10 + 48; while(len) pc(tmp[len--]); pc('.'); for(c *= 10; a; a--, c *= 10) pc(std::floor(c) - std::floor(c / 10) * 10 + 48); }
inline void write(const std::pair<int, double> x) { int a = x.first; if(a < 7) { double b = x.second, c = b; if(b < 0) pc('-'), b = -b, c = -c; double y = 5 * powl(10.0, -a - 1); b += y, c += y; int len = 0; char tmp[64]; if(b < 1) pc(48); else for(; b >= 1; b /= 10) tmp[++len] = std::floor(b) - std::floor(b / 10) * 10 + 48; while(len) pc(tmp[len--]); a ? (pc('.')) : void(); for(c *= 10; a; a--, c *= 10) pc(std::floor(c) - std::floor(c / 10) * 10 + 48); } else { flush(); std::cout << std::fixed << std::setprecision(a) << x.second; } }
inline void write(const char x) { pc(x); }
inline void write(const bool x) { pc(x ? 49 : 48); }
inline void write(char *x) { while (*x) pc(*x++); }
inline void write(const char *x) { while (*x) pc(*x++); }
inline void write(const std::string &x) { for (char c : x) pc(c); }
template<typename T, typename ...Tp> inline void write(T x, Tp ...y) { write(x), write(y...); }