版本比较
快读快写(卡常版)
正文
增加 3 行删除 29 行
12345345691078131491011121920131415161718192829202122232425263738272829304344313233343550363738395 行未改动4546474864495051523 行未改动5657585976606162633 行未改动676869708889717273746 行未改动81828384104105858687109110888990114115919293949512112296979899127100101102```cppnamespace FastIO { const int BUFFER_SIZE = 1 << 20; // 1MB 缓冲区 // 输入缓冲区 const int BUFFER_SIZE = 1 << 20; char in_buf[BUFFER_SIZE]; char *in_ptr = in_buf; char *in_end = in_buf; // 输出缓冲区 char out_buf[BUFFER_SIZE]; char *out_ptr = out_buf; // 从 stdin 读取数据到输入缓冲区 inline void load() { in_end = in_buf + fread(in_buf, 1, BUFFER_SIZE, stdin); in_ptr = in_buf; } // 获取一个字符(带缓冲) inline char getchar() { if (in_ptr == in_end) { load(); if (in_ptr == in_end) return EOF; } return *in_ptr++; } // 输出一个字符(带缓冲) inline void putchar(char c) { if (out_ptr == out_buf + BUFFER_SIZE) { fwrite(out_buf, 1, BUFFER_SIZE, stdout); out_ptr = out_buf; } *out_ptr++ = c; } // 刷新输出缓冲区 inline void flush() { fwrite(out_buf, 1, out_ptr - out_buf, stdout); out_ptr = out_buf; } // 读取整数(支持负数) template <typename T> inline bool read(T &x) { x = 0; char c = getchar(); bool negative = false; // 跳过空白字符 while (c != EOF && isspace(c)) c = getchar(); if (c == EOF) return false; if (c == '-') { negative = true;5 行未改动 } if (negative) x = -x; return true; } // 读取字符串(以空白字符分隔)(string) inline bool read(std::string &s) { s.clear(); char c = getchar(); while (c != EOF && isspace(c)) c = getchar();3 行未改动 c = getchar(); } return true; } // 读取字符串(以空白字符分隔)(char) inline bool read(char *s) { char c = getchar(); while (c != EOF && isspace(c)) c = getchar(); if (c == EOF) return false;3 行未改动 } *s = '\0'; return true; } // 输出整数 template <typename T> inline void write(T x) { if (x < 0) { putchar('-');6 行未改动 x /= 10; } while (x); while (len--) putchar(tmp[len]); } // 输出字符串 inline void write(const char *s) { while (*s) putchar(*s++); } // 输出换行 inline void writeln() { putchar('\n'); } // 输出整数并换行 template <typename T> inline void writeln(T x) { write(x); putchar('\n'); } // 输出字符串并换行 inline void writeln(const char *s) { write(s); putchar('\n'); }} // namespace FastIO}using namespace FastIO;```