一个巨巨提供的快读快输膜板
Uichiha_Itachi
2018-09-24 10:44:13
```cpp
#include <unistd.h>
#include <cstdarg>
#include <cctype>
#include <cstdio>
#include <ctime>
#include <cmath>
using namespace std;
#define dbg(x) write(#x " = "), write(x), write("\n")
#define getch() (maxip == ip ? EOF : (*ip++))
#define putch(x) (*op++) = (x)
#define writeln(...) write(__VA_ARGS__), putch('\n')
char inp[1 << 24], *ip = inp, *maxip;
char outp[1 << 20], *op = outp;
int readtime, precision = 6;
inline void main_init();
inline char getchigws();
template <typename T, typename... Args>
void read(T &x, Args &... args);
void read();
template <typename T>
void read(T &x);
template <>
void read<double>(double &x);
template <typename T, typename... Args>
void write(const T &x, const Args &... args);
void write();
template <typename T>
void write(const T &x);
template <>
void write<double>(const double &x);
void write(const char *s);
// define fast io
int main()
{
main_init();
#ifdef LOCAL
main_init();
fprintf(stderr, "Time used = %.2f\n",
(double)(clock() - readtime) / CLOCKS_PER_SEC);
sleep(1000);
#else
main_init();
#endif
return 0;
}
inline void main_init()
{
static bool inited = false;
if (inited)
fwrite(outp, 1, op - outp, stdout), op = outp;
else
{
maxip = ip + fread(inp, 1, sizeof(inp), stdin) + 1;
readtime = clock();
inited = true;
}
}
inline char getchigws()
{
char ch;
while (isspace(ch = getch()))
;
return ch;
}
template <typename T, typename... Args>
void read(T &x, Args &... args)
{
read(x);
read(args...);
}
void read() {}
template <typename T>
void read(T &x)
{
T f = 1;
int ch;
while (!isdigit(ch = getch()) && ch != EOF)
if (ch == '-')
f = -1;
x = 0;
while (isdigit(ch) && ch != EOF)
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getch();
ip--;
x *= f;
}
template <>
void read<double>(double &x)
{
double l = 0, r = 0, f = 1;
int s = 0, ch;
while (!isdigit(ch = getch()) && ch != EOF)
if (ch == '-')
f = -1;
while (isdigit(ch) && ch != EOF)
{
l = l * 10 + (ch ^ 48);
ch = getch();
}
if (ch == '.')
while (isdigit(ch = getch()) && ch != EOF)
r = r * 10 + (ch ^ 48), s++;
ip--;
x = (l + r / pow(10, s)) * f;
}
template <typename T, typename... Args>
void write(const T &x, const Args &... args)
{
write(x);
write(args...);
}
void write() {}
template <typename T>
void write(const T &x)
{
if (x < 0)
putch('-'), write(-x);
else
{
if (x >= 10)
write(x / 10);
putch(x % 10 ^ 48);
}
}
template <>
void write<double>(const double &x)
{
if (x == 0)
{
write("0.");
for (int i = 0; i < precision; i++)
putch('0');
return;
}
if (x < 0)
putch('-'), write(-x);
else
{
double r = x - floor(x), l = floor(x);
if (l == 0)
putch('0');
char buf[310];
int i = 0;
while (floor(l) != 0)
{
buf[i++] = floor(l - floor(l / 10) * 10);
l /= 10;
}
for (int j = i - 1; j >= 0; j--)
putch(buf[j] ^ 48);
putch('.');
for (int i = 0; i < precision - 1; i++)
putch(int(floor(r *= 10)) ^ 48), r -= floor(r);
double tmp = r * 10;
if (int(floor(tmp * 10 - floor(tmp) * 10)) >= 5)
putch((int(floor(tmp)) + 1) ^ 48);
else
putch(int(floor(tmp)) ^ 48);
}
}
void write(const char *s)
{
while (*s)
putch(*s++);
}
```
$O^{r^z}_{T_Z}$