-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFastIO.cpp
More file actions
62 lines (61 loc) · 1.1 KB
/
FastIO.cpp
File metadata and controls
62 lines (61 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
struct bufferedreader {
char* buffer;
int i = 0, idx = 0;
bufferedreader() {
buffer = new char[1 << 22];
}
void readinput() {
idx = fread(buffer, 1, 1 << 22, stdin);
i = 0;
}
int readint() {
int ret = 0, chk = 0;
if (i == idx) readinput();
if (buffer[i] == '-') {
chk = 1, i++;
}
if (i == idx) readinput();
while (i < idx && (buffer[i] >= '0' && buffer[i] <= '9')) {
ret = ret * 10 + (buffer[i] - '0'), i++;
if (i == idx) readinput();
}
return i++, chk ? -ret : ret;
}
~bufferedreader() {
delete[] buffer;
}
};
struct bufferedwriter {
char* buffer;
int i = 0;
bufferedwriter() {
buffer = new char[1 << 22];
}
void writeoutput() {
fwrite(buffer, 1, i, stdout);
}
void check() {
if (i == (1 << 22)) {
writeoutput(), i = 0;
}
}
void writeint(int x) {
int temp[15], j = 0;
if (x < 0) buffer[i++] = '-', x = -x;
check();
if (!x) temp[j++] = 0;
while (x) {
temp[j++] = x % 10;
x /= 10;
}
for (int k = j - 1; k >= 0; k--) {
buffer[i++] = temp[k] + '0';
check();
}
buffer[i++] = ' ';
check();
}
~bufferedwriter() {
delete[] buffer;
}
};