Fastio
好用的快读
快读
struct Fastio
{
template <typename T>
inline Fastio operator>>(T &x)
{
x = 0;
char c = getchar();
while (c < '0' || c > '9')
c = getchar();
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return *this;
}
template <typename T>
inline Fastio operator>>(T &x)
{
x = 0;
char c = getchar();
while (c < '0' || c > '9')
c = getchar();
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return *this;
}
} io;
快读
增加字符和字符串。
struct Fastio
{
template <typename T>
inline Fastio operator>>(T &x)
{
x = 0;
char c = getchar();
while (c < '0' || c > '9')
c = getchar();
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return *this;
}
inline Fastio &operator<<(const char c)
{
putchar(c);
return *this;
}
inline Fastio &operator<<(const char *str)
{
int cur = 0;
while (str[cur])putchar(str[cur++]);
return *this;
}
template <typename T>
inline Fastio &operator<<(T x)
{
if (x == 0)
{
putchar('0');
return *this;
}
if (x < 0) putchar('-'), x = -x;
static int sta[45];
int top = 0;
while (x) sta[++top] = x % 10, x /= 10;
while (top) putchar(sta[top] + '0'), --top;
return *this;
}
} io;
快读
在快读 的基础上重定义 getchar()
和 putchar()
。
namespace fastio
{
int len = 0;
char ibuf[(1 << 20) + 1], *iS, *iT, out[(1 << 23) + 1];
#if ONLINE_JUDGE
#define getchar() (iS == iT) ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin), (iS == iT ? EOF : *iS++) : *iS++)
int read()
{
int x = 0, t = 0;
char c = getchar();
while(c < '0' || c > '9')
{
t |= ch == '-';
c = getchar();
}
while(c >= '0' && c <= '9')
{
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return t ? -x : x;
}
char getcA()
{
char c = getchar();
while(c < 'A' || c > 'Z') c = getchar();
return c;
}
char getca()
{
char c = getchar();
while(c < 'a' || c > 'z') c = getchar();
return c;
}
void putc(char c)
{
out[len++] = c;
}
void write(int x)
{
it(x < 0) putc('-'), x = -x;
if(x > 9) write(x / 10);
putc(x % 10 + 48);
}
struct af
{
~af()
{
fwrite(out, 1, len, stdout);
len = 0;
}
}Af;
}
using namespace fastio;
快读
复杂度巨大。
/* --------------- fast io --------------- */ // begin
namespace Fastio
{
namespace Fread
{
const int SIZE = 1 << 21;
char buf[SIZE], *S, *T;
inline char getchar()
{
if (S == T)
{
T = (S = buf) + fread(buf, 1, SIZE, stdin);
if (S == T)
return '\n';
}
return *S++;
}
} // namespace Fread
namespace Fwrite
{
const int SIZE = 1 << 21;
char buf[SIZE], *S = buf, *T = buf + SIZE;
inline void flush()
{
fwrite(buf, 1, S - buf, stdout);
S = buf;
}
inline void putchar(char c)
{
*S++ = c;
if (S == T)
flush();
}
struct NTR
{
~NTR() { flush(); }
} ztr;
} // namespace Fwrite
#ifdef ONLINE_JUDGE
#define getchar Fread ::getchar
#define putchar Fwrite ::putchar
#endif
struct Reader
{
template <typename T>
Reader &operator>>(T &x)
{
char c = getchar();
T f = 1;
while (c < '0' || c > '9')
{
if (c == '-')
f = -1;
c = getchar();
}
x = 0;
while (c >= '0' && c <= '9')
{
x = x * 10 + (c - '0');
c = getchar();
}
x *= f;
return *this;
}
Reader &operator>>(char &c)
{
c = getchar();
while (c == ' ' || c == '\n')
{
c = getchar();
}
return *this;
}
Reader &operator>>(char *str)
{
int len = 0;
char c = getchar();
while (c == ' ' || c == '\n')
{
c = getchar();
}
while (c != ' ' && c != '\n' && c != '\r')
{ // \r\n in windows
str[len++] = c;
c = getchar();
}
str[len] = '\0';
return *this;
}
Reader() {}
} cin;
const char endl = '\n';
struct Writer
{
template <typename T>
Writer &operator<<(T x)
{
if (x == 0)
{
putchar('0');
return *this;
}
if (x < 0)
{
putchar('-');
x = -x;
}
static int sta[111];
int top = 0;
while (x)
{
sta[++top] = x % 10;
x /= 10;
}
while (top)
{
putchar(sta[top] + '0');
--top;
}
return *this;
}
Writer &operator<<(char c)
{
putchar(c);
return *this;
}
Writer &operator<<(char *str)
{
int cur = 0;
while (str[cur])
putchar(str[cur++]);
return *this;
}
Writer &operator<<(const char *str)
{
int cur = 0;
while (str[cur])
putchar(str[cur++]);
return *this;
}
Writer() {}
} cout;
#define cin Fastio ::cin
#define cout Fastio ::cout
#define endl Fastio ::endl
} // namespace Fastio
/* --------------- fast io --------------- */ // end
快读
支持高精度运算和高精度快读,但不支持高精度位运算。
const int N = 1e4 + 5;
struct GJ
{
int d[N];
int len;
void clean()
{
while (len > 1 && !d[len - 1])
len--;
}
GJ()
{
memset(d, 0, sizeof d);
}
GJ(int num)
{
*this = num;
}
GJ(char *num)
{
*this = num;
}
GJ operator=(const char *num)
{
memset(d, 0, sizeof d);
len = strlen(num);
for (int i = 0; i < len; i++)
d[i] = num[len - 1 - i] - '0';
clean();
return *this;
}
GJ operator=(int num)
{
char s[101];
sprintf(s, "%d", num);
*this = s;
return *this;
}
GJ operator=(long long num)
{
char s[202];
sprintf(s, "%lld", num);
*this = s;
return *this;
}
GJ operator=(string num)
{
memset(d, 0, sizeof d);
len = num.length();
for (int i = 0; i < len; i++)
d[i] = num[len - 1 - i] - '0';
clean();
return *this;
}
GJ operator+(const GJ &b)
{
GJ c = *this;
int i;
for (i = 0; i < b.len; i++)
{
c.d[i] += b.d[i];
if (c.d[i] > 9)
{
c.d[i] %= 10;
c.d[i + 1]++;
}
}
while (c.d[i] > 9)
{
c.d[i++] %= 10;
c.d[i]++;
}
c.len = max(len, b.len);
if (c.d[i] && c.len <= i)
c.len = i + 1;
return c;
}
GJ operator-(const GJ &b)
{
GJ c = *this;
int i;
for (i = 0; i < b.len; i++)
{
c.d[i] -= b.d[i];
if (c.d[i] < 0)
{
c.d[i] += 10;
c.d[i + 1]--;
}
}
while (c.d[i] < 0)
{
c.d[i++] += 10;
c.d[i]--;
}
c.clean();
return c;
}
GJ operator*(const GJ &b) const
{
int i, j;
GJ c;
c.len = len + b.len;
for (j = 0; j < b.len; j++)
for (i = 0; i < len; i++)
c.d[i + j] += d[i] * b.d[j];
for (i = 0; i < c.len - 1; i++)
{
c.d[i + 1] += c.d[i] / 10;
c.d[i] %= 10;
}
c.clean();
return c;
}
GJ operator/(const GJ &b)
{
int i, j;
GJ c = *this, a = 0;
for (i = len - 1; i >= 0; i--)
{
a = a * 10 + d[i];
for (j = 0; j < 10; j++)
{
if (a < b * (j + 1))
break;
}
c.d[i] = j;
a = a - b * j;
}
c.clean();
return c;
}
GJ operator%(const GJ &b)
{
int i, j;
GJ a = 0;
for (i = len - 1; i >= 0; i--)
{
a = a * 10 + d[i];
for (j = 0; j < 10; j++)
{
if (a < b * (j + 1))
break;
}
a = a - b * j;
}
return a;
}
GJ operator+=(const GJ &b)
{
*this = *this + b;
return *this;
}
GJ operator-=(const GJ &b)
{
*this = *this - b;
return *this;
}
bool operator<(const GJ &b) const
{
if (len != b.len)
return len < b.len;
for (int i = len - 1; i >= 0; i--)
if (d[i] != b.d[i])
return d[i] < b.d[i];
return false;
}
bool operator>(const GJ &b) const { return b < *this; }
bool operator<=(const GJ &b) const { return !(b < *this); }
bool operator>=(const GJ &b) const { return !(*this < b); }
bool operator!=(const GJ &b) const { return b < *this || *this < b; }
bool operator==(const GJ &b) const { return !(b < *this) && !(b > *this); }
string str() const
{
char s[N] = {};
for (int i = 0; i < len; i++)
s[len - 1 - i] = d[i] + '0';
return s;
}
};
/* --------------- fast io --------------- */ // begin
namespace Fread
{
const int SIZE = 1 << 21;
char buf[SIZE], *S, *T;
inline char getchar()
{
if (S == T)
{
T = (S = buf) + fread(buf, 1, SIZE, stdin);
if (S == T)
return '\n';
}
return *S++;
}
} // namespace Fread
namespace Fwrite
{
const int SIZE = 1 << 21;
char buf[SIZE], *S = buf, *T = buf + SIZE;
inline void flush()
{
fwrite(buf, 1, S - buf, stdout);
S = buf;
}
inline void putchar(char c)
{
*S++ = c;
if (S == T)
flush();
}
struct NTR
{
~NTR() { flush(); }
} ztr;
} // namespace Fwrite
#ifdef ONLINE_JUDGE
#define getchar Fread ::getchar
#define putchar Fwrite ::putchar
#endif
namespace Fastio
{
struct Doublee
{
double x;
int k = 6;
};
struct Reader
{
template <typename T>
Reader &operator>>(T &x)
{
char c = getchar();
T f = 1;
while (c < '0' || c > '9')
{
if (c == '-')
f = -1;
c = getchar();
}
x = 0;
while (c >= '0' && c <= '9')
{
x = x * 10 + (c - '0');
c = getchar();
}
x *= f;
return *this;
}
Reader &operator>>(double &num)
{
char in;
double Dec = 0.1;
bool IsN = false, IsD = false;
in = getchar();
if (in == EOF)
{
return *this;
}
while (in != '-' && in != '.' && (in < '0' || in > '9'))
{
in = getchar();
}
if (in == '-')
{
IsN = true;
num = 0;
}
else if (in == '.')
{
IsD = true;
num = 0;
}
else
{
num = in - '0';
}
if (!IsD)
{
while (in = getchar(), in >= '0' && in <= '9')
{
num *= 10;
num += in - '0';
}
}
if (in != '.')
{
if (IsN)
num = -num;
}
else
{
while (in = getchar(), in >= '0' && in <= '9')
{
num += Dec * (in - '0');
Dec *= 0.1;
}
}
if (IsN)
{
num = -num;
}
}
Reader &operator>>(char &c)
{
c = getchar();
while (c == ' ' || c == '\n')
{
c = getchar();
}
return *this;
}
Reader &operator>>(char *str)
{
int len = 0;
char c = getchar();
while (c == ' ' || c == '\n')
{
c = getchar();
}
while (c != ' ' && c != '\n' && c != '\r')
{ // \r\n in windows
str[len++] = c;
c = getchar();
}
str[len] = '\0';
return *this;
}
Reader &operator>>(GJ &x)
{
string str = "";
char c = getchar();
while (c == ' ' || c == '\n')
{
c = getchar();
}
while (c != ' ' && c != '\n' && c != '\r')
{ // \r\n in windows
str += c;
c = getchar();
}
//cout << str.c_str();
x = str.c_str();
return *this;
}
Reader() {}
} cin;
const char endl = '\n';
struct Writer
{
Writer &operator<<(Doublee op)
{
static int n = pow(10, op.k);
if (op.x == 0)
{
putchar('0'), putchar('.');
for (int i = 1; i <= op.k; ++i)
putchar('0');
return *this;
}
if (op.x < 0)
putchar('-'), op.x = -op.x;
long long y = (long long)(op.x * n) % n;
op.x = (long long)op.x;
cout << op.x;
putchar('.');
int bit[10], p = 0, i;
for (; p < op.k; y /= 10)
bit[++p] = y % 10;
for (i = p; i > 0; i--)
putchar(bit[i] + 48);
return *this;
}
template <typename T>
Writer &operator<<(T x)
{
if (x == 0)
{
putchar('0');
return *this;
}
if (x < 0)
{
putchar('-');
x = -x;
}
static int sta[111];
int top = 0;
while (x)
{
sta[++top] = x % 10;
x /= 10;
}
while (top)
{
putchar(sta[top] + '0');
--top;
}
return *this;
}
Writer &operator<<(char c)
{
putchar(c);
return *this;
}
Writer &operator<<(char *str)
{
int cur = 0;
while (str[cur])
putchar(str[cur++]);
return *this;
}
Writer &operator<<(const char *str)
{
int cur = 0;
while (str[cur])
putchar(str[cur++]);
return *this;
}
Writer &operator<<(const GJ &x)
{
string str = x.str();
int cur = 0;
while (str[cur])
putchar(str[cur++]);
return *this;
}
Writer() {}
} cout;
} // namespace Fastio
#define cin Fastio ::cin
#define cout Fastio ::cout
#define endl Fastio ::endl
/* --------------- fast io --------------- */ // end
本文来自博客园,作者:蒟蒻orz,转载请注明原文链接:https://www.cnblogs.com/orzz/p/18122149
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话