Code
// unlocked putchar, getchar
// #define LOCAL
#ifdef LOCAL
#define getchar_unlocked getchar
#define putchar_unlocked putchar
#endif
template<class T>
inline T read() {
T x = 0, f = 1;
char ch = getchar_unlocked();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar_unlocked();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch ^ 48);
ch = getchar_unlocked();
}
return x * f;
}
template<class T>
inline void write(T x) {
if (x < 0) {
putchar_unlocked('-');
x = -x;
}
if (x > 9) write(x / 10);
putchar_unlocked(x % 10 + '0');
return;
}
Usage
读入一个整数用 x = read<T>()
,其中 T
为 x
的类型.
输出一个整数用 write(x)
.
在 windows
本地调试时,需要将 #define LOCAL
那行的注释去掉.
Example
读入 n n n 个整数,输出它们的和.
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
const int n = read<int>();
i64 res = 0;
for (int i = 0; i < n; i++) res += read<int>();
write(res), putchar_unlocked('\n');
return 0;
}