提供一份非常优秀的快读模板
namespace IN {
const int MAX_INPUT = 1000000;
#define getc() (p1 == p2 && (p2 = (p1 = buf) + inbuf -> sgetn(buf, MAX_INPUT), p1 == p2) ? EOF : *p1++)
char buf[MAX_INPUT], *p1, *p2;
template <typename T> inline bool redi(T &x) {
static streambuf *inbuf = cin.rdbuf();
x = 0;
register int f = 0, flag = false;
register char ch = getc();
while (!isdigit(ch)) {
if (ch == '-') f = 1;
ch = getc();
}
if (isdigit(ch)) x = x * 10 + ch - '0', ch = getc(),flag = true;
while (isdigit(ch)) {
x = x * 10 + ch - 48;
ch = getc();
}
x = f ? -x : x ;
return flag;
}
template <typename T,typename ...Args> inline bool redi(T& a,Args& ...args) {
return redi(a) && redi(args...);
}
#undef getc
}
using IN::redi;
读入用redi(...)
我的TLE代码1.70s->1.44s