WELCOME

任何一个伟大的目标,都有一个微不足道的开始。

C++ 加速(卡常)技巧【超级 快读、快写】

C++ \texttt{C++} C++ 加速技巧

快读快写

快读

inline int read()
{
    int x = 0, w = 0; char ch = 0;
    while (!isdigit(ch)) {w |= ch == '-'; ch = getchar();}
    while (isdigit(ch)) {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
    return w ? -x : x;
}

快写

inline void write(int x)
{
     if (x < 0) putchar('-'), x = -x;
     if (x > 9) write(x / 10);
     putchar(x % 10 + '0');
}

超级快读快写

namespace IO

{
int len = 0;
char ibuf[(1 << 20) + 1], *iS, *iT, out[(1 << 25) + 1];
#define gh()                                                                   \
	(iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin),       \
	(iS == iT ? EOF : *iS++) : *iS++)
#define reg register
inline int read()
{
	reg char ch = gh();
	reg int x = 0;
	reg char t = 0;
	while (ch < '0' || ch > '9')
		t |= ch == '-', ch = gh();
	while (ch >= '0' && ch <= '9')
		x = x * 10 + (ch ^ 48), ch = gh();
	return t ? -x : x;
}
inline void putc(char ch)
{
	out[len++] = ch;
}
template <class T> inline void write(T x)
{
	if (x < 0)
		putc('-'), x = -x;
	if (x > 9)
		write(x / 10);
	out[len++] = x % 10 + 48;
}
inline void flush()
{
	fwrite(out, 1, len, stdout);
	len = 0;
}
}
using IO::flush;
using IO::putc;
using IO::read;
using IO::write;

广告

绿树公司 - 官方网站:https://wangping-lvshu.github.io/LvshuNew/

绿树智能 - 官方网站:https://wangping-lvshu.github.io/LvshuZhineng/

(现在使用,人人均可获得300元大奖)

posted @ 2022-07-12 20:35  绿树公司  阅读(972)  评论(0)    收藏  举报