-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path#_template_c-cpp.cpp
111 lines (101 loc) · 2.21 KB
/
#_template_c-cpp.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <iostream>
#define ll long long
// fast integer read & write
int read() {
int s = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -f;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
s = (s << 1) + (s << 3) + (ch ^ '0');
ch = getchar();
}
return s * f;
}
void write(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9) {
write(x / 10);
putchar(x % 10 + '0');
} else putchar(x + '0');
return;
}
void disable() { // C++ disables the io synchronization
std::ios_base::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);
}
// fast long readL & writeL
ll readL() {
ll s = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -f;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
s = (s << 1) + (s << 3) + (ch ^ '0');
ch = getchar();
}
return s * f;
}
void writeL(ll x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9) {
writeL(x / 10);
putchar(x % 10 + '0');
} else putchar(x + '0');
return;
}
// fast char array read, begin from str[0]
int readChs(char str[]) {
int len = -1;
char ch = getchar();
while (ch == ' ' || ch == '\n' || ch == '\r') {
ch = getchar();
}
while (ch != ' ' && ch != '\n' && ch != '\r') {
str[++len] = ch;
ch = getchar();
}
return len;
}
// "fast string" read
std::string readStr() {
std::string str;
char s = getchar();
while (s == ' ' || s == '\n' || s == '\r') {
s = getchar();
}
while (s != ' ' && s != '\n' && s != '\r') {
str += s;
s = getchar();
}
return str;
}
// fast generic & varargs read
template<typename T>
inline void readT(T &x) {
T s = 0, f = 1;
T ch = getchar();
while (!std::isdigit(ch)) {
if (ch == '-') f = -f;
ch = getchar();
}
while (std::isdigit(ch)) {
s = (s << 1) + (s << 3) + (ch ^ '0');
ch = getchar();
}
x = s * f;
}
template<typename T, typename ...Args>
inline void readTs(T &x, Args &...args) {
readT(x);
readTs(args...);
}