#include <cstdio>
#include <cstddef>
#include <cstring>
#include <cstdint>
#include <cassert>
namespace hint
{
class ItoStrBase10000
{
private:
uint32_t table[10000]{};
public:
static constexpr uint32_t itosbase10000(uint32_t num)
{
uint32_t res = (num / 1000 % 10) | ((num / 100 % 10) << 8) |
((num / 10 % 10) << 16) | ((num % 10) << 24);
return res + '0' * 0x1010101;
}
constexpr ItoStrBase10000()
{
for (size_t i = 0; i < 10000; i++)
{
table[i] = itosbase10000(i);
}
}
void tostr(char *str, uint32_t num) const
{
// *reinterpret_cast<uint32_t *>(str) = table[num];
std::memcpy(str, &table[num], sizeof(num));
}
uint32_t tostr(uint32_t num) const
{
return table[num];
}
};
class StrtoIBase100
{
private:
static constexpr size_t TABLE_SIZE = size_t(1) << 15;
uint16_t table[TABLE_SIZE]{};
public:
static constexpr uint16_t itosbase100(uint16_t num)
{
uint16_t res = (num / 10 % 10) | ((num % 10) << 8);
return res + '0' * 0x0101;
}
constexpr StrtoIBase100()
{
for (size_t i = 0; i < TABLE_SIZE; i++)
{
table[i] = UINT16_MAX;
}
for (size_t i = 0; i < 100; i++)
{
table[itosbase100(i)] = i;
}
}
uint16_t toInt(const char *str) const
{
uint16_t num;
std::memcpy(&num, str, sizeof(num));
return table[num];
}
};
static const ItoStrBase10000 itos4{};
static const StrtoIBase100 stoi2{};
class FastOut
{
private:
static constexpr size_t BUFFER_SIZE = size_t(1) << 12, FILE_BUFFER_SIZE = size_t(1) << 15, END_SPACE = 32;
static constexpr size_t TEN2 = 1e2, TEN3 = 1e3, TEN4 = 1e4, TEN8 = 1e8, TEN12 = 1e12, TEN16 = 1e16;
FILE *fd;
char *ptr;
char *const output_end;
bool is_file = false;
alignas(32) char buffer[BUFFER_SIZE];
alignas(4096) char file_buffer[FILE_BUFFER_SIZE];
// 0 - 99
void out12(uint32_t x)
{
if (x < 10)
{
*ptr++ = '0' + x;
}
else
{
ptr[0] = '0' + x / 10;
ptr[1] = '0' + x % 10;
ptr += 2;
}
}
void out1To4(uint32_t x)
{
if (x < TEN2)
{
out12(x);
}
else if (x < TEN3) // 100 - 999
{
itos4.tostr(ptr, x * 10);
ptr += 3;
}
else
{
out4(x);
}
}
void out1To8(uint32_t x)
{
if (x >= TEN4) // 10000 - 99999999
{
uint32_t xh = x / TEN4, xl = x % TEN4;
out1To4(xh);
out4(xl);
}
else // 0 - 9999
{
out1To4(x);
}
}
// 1000 - 9999
void out4(uint32_t x)
{
itos4.tostr(ptr, x);
ptr += 4;
}
// 10000000 - 99999999
void out8(uint32_t x)
{
itos4.tostr(ptr, x / TEN4);
itos4.tostr(ptr + 4, x % TEN4);
ptr += 8;
}
void flushToFile()
{
fwrite(buffer, 1, ptr - buffer, fd);
ptr = buffer;
}
void fullFlush()
{
if (ptr >= output_end) [[unlikely]]
{
flushToFile();
}
}
public:
FastOut(FILE *out) : fd(out), buffer{}, file_buffer{},
ptr(buffer),
output_end(buffer + BUFFER_SIZE)
{
assert(fd);
enableBuffer();
}
void enableBuffer()
{
setvbuf(fd, file_buffer, _IOFBF, sizeof(file_buffer));
}
FastOut(const char *out) : FastOut(fopen(out, "w")) { is_file = true; }
~FastOut()
{
flush();
if (is_file)
{
fclose(fd);
}
}
void flush()
{
flushToFile();
fflush(fd);
}
FastOut &operator<<(int x)
{
if (x < 0)
{
*ptr = '-';
ptr++;
x = -x;
}
if (x >= TEN8)
{
uint32_t xh = x / TEN8, xl = x % TEN8;
out12(xh);
out8(xl);
}
else // 0 - 99999999
{
out1To8(x);
}
fullFlush();
return *this;
}
FastOut &operator<<(char c)
{
*ptr++ = c;
return *this;
}
};
class FastIn
{
private:
static constexpr size_t BUFFER_SIZE = size_t(1) << 15, END_SPACE = 32;
static constexpr size_t TEN2 = 1e2, TEN3 = 1e3, TEN4 = 1e4, TEN8 = 1e8, TEN12 = 1e12, TEN16 = 1e16;
FILE *fd;
const char *ptr;
bool is_file = false;
alignas(32) char buffer[BUFFER_SIZE];
int skipSpace()
{
int sign = 1;
while (*ptr <= '-')
{
sign = *ptr - '-';
ptr++;
}
return sign;
}
public:
FastIn(FILE *out) : fd(out), buffer{},
ptr(buffer)
{
assert(fd);
size_t count = fread(buffer, 1, sizeof(buffer), fd);
assert(count < sizeof(buffer));
}
FastIn(const char *in) : FastIn(fopen(in, "r")) { is_file = true; }
~FastIn()
{
if (is_file)
{
fclose(fd);
}
}
template <typename T>
FastIn &operator>>(T &x)
{
int sign = skipSpace();
x = 0;
int n;
while (true)
{
n = stoi2.toInt(ptr);
if (n >= 100)
{
break;
}
x *= 100;
x += n;
ptr += 2;
}
n = *ptr - '0';
if (n >= 0)
{
x *= 10;
x += n;
ptr++;
}
if (sign == 0)
{
x = -x;
}
return *this;
}
FastIn &operator>>(char &c)
{
c = *ptr;
ptr++;
return *this;
}
FastIn &operator>>(const char *str)
{
return *this;
}
};
static FastIn qin(stdin);
static FastOut qout(stdout);
}
using hint::qin;
using hint::qout;
int main()
{
int n;
qin >> n;
while (n--)
{
int a, b;
qin >> a >> b;
qout << a + b << '\n';
}
qout.flush();
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 24.39 us | 104 KB | Accepted | Score: 100 | 显示更多 |