-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfast_io.cpp
executable file
·66 lines (55 loc) · 1.16 KB
/
fast_io.cpp
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
63
64
65
66
/**
Fast Input/Output method for C++:
1. cin(with sync_with_stdio(false) & cin.tie(nullptr)):
- int:
- |n = 5e6| => 420ms
- |n = 1e7| => 742ms
- ll:
- |n = 5e6| => 895ms
2. read (using getchar()):
- int:
- |n = 5e6| => 173ms
- |n = 1e7| => 172ms
- ll:
- |n = 5e6| => 340ms
**/
ll readll () {
bool minus = false;
unsigned long long result = 0;
char ch;
ch = getchar();
while (true) {
if (ch == '-') break;
if (ch >= '0' && ch <= '9') break;
ch = getchar();
}
if (ch == '-') minus = true;
else result = ch - '0';
while (true) {
ch = getchar();
if (ch < '0' || ch > '9') break;
result = result * 10 + (ch - '0');
}
if (minus) return -(ll)result;
return result;
}
int readi () {
bool minus = false;
unsigned int result = 0;
char ch;
ch = getchar();
while (true) {
if (ch == '-') break;
if (ch >= '0' && ch <= '9') break;
ch = getchar();
}
if (ch == '-') minus = true;
else result = ch - '0';
while (true) {
ch = getchar();
if (ch < '0' || ch > '9') break;
result = result * 10 + (ch - '0');
}
if (minus) return -(int)result;
return result;
}