Skip to content

Commit d38a1b0

Browse files
committed
feat: Enhance FastIO with debug mode and add many_aplusb_debug test
1 parent 0a6750f commit d38a1b0

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

test/many_aplusb.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "../weilycoder/fast-io.hpp"
44
using namespace weilycoder;
55

6-
static FastIODefault io;
6+
static FastIODefault<> io;
77

88
int main() {
99
size_t t = io.read_u64();

test/many_aplusb_debug.test.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#define PROBLEM "https://judge.yosupo.jp/problem/many_aplusb"
2+
3+
#include "../weilycoder/fast-io.hpp"
4+
using namespace weilycoder;
5+
6+
static FastIODefault<true> io;
7+
8+
int main() {
9+
size_t t = io.read_u64();
10+
while (t--) {
11+
uint64_t a = io.read_u64();
12+
uint64_t b = io.read_u64();
13+
uint64_t c = a + b;
14+
io.write_u64_line(c);
15+
}
16+
return 0;
17+
}

weilycoder/fast-io.hpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ template <size_t buffer_size = 1 << 20> struct FastWriteFWrite {
6969
void operator()(char c) { putchar(c); }
7070
};
7171

72-
template <typename Reader, typename Writer> struct FastIO {
72+
template <typename Reader, typename Writer, bool debug = false> struct FastIO {
7373
Reader reader;
7474
Writer writer;
7575

@@ -78,8 +78,19 @@ template <typename Reader, typename Writer> struct FastIO {
7878
FastIO(const FastIO &) = delete;
7979
FastIO &operator=(const FastIO &) = delete;
8080

81-
char getchar() { return reader.getchar(); }
82-
void putchar(char c) { writer.putchar(c); }
81+
char getchar() {
82+
if constexpr (debug)
83+
return std::getchar();
84+
else
85+
return reader.getchar();
86+
}
87+
88+
void putchar(char c) {
89+
if constexpr (debug)
90+
std::putchar(c), std::fflush(stdout);
91+
else
92+
writer.putchar(c);
93+
}
8394

8495
void flush() { writer.flush(); }
8596

@@ -108,7 +119,8 @@ template <typename Reader, typename Writer> struct FastIO {
108119
void write_u64_line(uint64_t x) { write_u64(x), putchar('\n'); }
109120
};
110121

111-
using FastIODefault = FastIO<FastReadMMap, FastWriteFWrite<>>;
122+
template <bool debug = false>
123+
using FastIODefault = FastIO<FastReadMMap, FastWriteFWrite<>, debug>;
112124
} // namespace weilycoder
113125

114126
#endif

0 commit comments

Comments
 (0)