proconlib

This documentation is automatically generated by competitive-verifier/competitive-verifier

View the Project on GitHub anqooqie/proconlib

:heavy_check_mark: tests/fastio/integer.test.cpp

Depends on

Code

// competitive-verifier: PROBLEM https://judge.yosupo.jp/problem/many_aplusb

#include <iostream>
#include "tools/cin.hpp"
#include "tools/cout.hpp"

using ll = long long;

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);

  int T;
  tools::cin >> T;
  for (int i = 0; i < T; ++i) {
    ll A, B;
    tools::cin >> A >> B;
    tools::cout << A + B << '\n';
  }

  return 0;
}
#line 1 "tests/fastio/integer.test.cpp"
// competitive-verifier: PROBLEM https://judge.yosupo.jp/problem/many_aplusb

#include <iostream>
#line 1 "tools/cin.hpp"



#include <cstring>
#include <cstdio>
#include <string>
#include <algorithm>
#include <type_traits>
#line 10 "tools/cin.hpp"
#include <utility>

// Source: https://nyaannyaan.github.io/library/misc/fastio.hpp.html
// License: CC0 1.0 Universal
// Author: Nyaan

namespace tools {
  namespace detail {
    namespace istream {
      static constexpr int SZ = 1 << 17;
      char inbuf[SZ];
      int in_left = 0;
      int in_right = 0;

      void load() {
        const int len = in_right - in_left;
        ::std::memmove(inbuf, inbuf + in_left, len);
        in_right = len + ::std::fread(inbuf + len, 1, SZ - len, stdin);
        in_left = 0;
      }

      void skip_space() {
        if (in_left + 32 > in_right) load();
        while (inbuf[in_left] <= ' ') in_left++;
      }

      void rd(char& c) {
        if (in_left + 32 > in_right) load();
        c = inbuf[in_left++];
      }

      void rd(::std::string& s) {
        for (; (in_left < in_right || (load(), in_left < in_right)) && (inbuf[in_left] == ' ' || inbuf[in_left] == '\n'); ++in_left);
        s.clear();
        if (in_left == in_right) return;
        int real_size = 0;
        do {
          int to;
          for (to = in_left; to < in_right && inbuf[to] != ' ' && inbuf[to] != '\n'; ++to);
          const int new_real_size = real_size + (to - in_left);
          if (int(s.size()) < new_real_size) {
            s.resize(::std::max(new_real_size, int(s.size()) * 2));
          }
          ::std::memcpy(s.data() + real_size, inbuf + in_left, to - in_left);
          in_left = to;
          real_size = new_real_size;
        } while (in_left == in_right && (load(), in_left < in_right));
        s.resize(real_size);
      }

      template <typename T>
      void rd(T& x) {
        if (in_left + 32 > in_right) load();
        char c;
        do {
          c = inbuf[in_left++];
        } while (c < '-');
        [[maybe_unused]] bool minus = false;
        if constexpr (::std::is_signed_v<T>) {
          if (c == '-') {
            minus = true;
            c = inbuf[in_left++];
          }
        }
        x = 0;
        while (c >= '0') {
          x = x * 10 + (c & 15);
          c = inbuf[in_left++];
        }
        if constexpr (::std::is_signed_v<T>) {
          if (minus) x = -x;
        }
      }
    }
  }

  struct istream {
    template <typename... Args>
    ::tools::istream& operator>>(Args&&... args) {
      ::tools::detail::istream::rd(::std::forward<Args>(args)...);
      return *this;
    }
  };

  ::tools::istream cin;
}


#line 1 "tools/cout.hpp"



#line 9 "tools/cout.hpp"
#include <cstdint>
#include <cstdlib>
#line 13 "tools/cout.hpp"

// Source: https://nyaannyaan.github.io/library/misc/fastio.hpp.html
// License: CC0 1.0 Universal
// Author: Nyaan

namespace tools {
  namespace detail {
    namespace ostream {
      static constexpr int SZ = 1 << 17;
      char outbuf[SZ];
      int out_right = 0;

      struct Pre {
        char num[40000];
        constexpr Pre() : num() {
          for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
              num[i * 4 + j] = n % 10 + '0';
              n /= 10;
            }
          }
        }
      } constexpr pre;

      void flush() {
        ::std::fwrite(outbuf, 1, out_right, stdout);
        out_right = 0;
      }

      void wt(const char c) {
        if (out_right > SZ - 32) flush();
        outbuf[out_right++] = c;
      }

      void wt(const bool b) {
        if (out_right > SZ - 32) flush();
        outbuf[out_right++] = b ? '1' : '0';
      }

      void wt(const ::std::string& s) {
        for (int l = 0, w; l < int(s.size()); l += w) {
          w = ::std::min(int(s.size()) - l, SZ - out_right);
          ::std::memcpy(outbuf + out_right, s.data() + l, w);
          out_right += w;
          if (out_right == SZ) flush();
        }
      }

      void wt(const char * const s) {
        wt(::std::string(s));
      }

      template <typename T>
      void wt(T x) {
        if (out_right > SZ - 32) flush();
        if (!x) {
          outbuf[out_right++] = '0';
          return;
        }
        if constexpr (::std::is_signed_v<T>) {
          if (x < 0) {
            outbuf[out_right++] = '-';
            x = -x;
          }
        }
        int i = 12;
        char buf[16];
        while (x >= 10000) {
          ::std::memcpy(buf + i, pre.num + (x % 10000) * 4, 4);
          x /= 10000;
          i -= 4;
        }
        if (x < 100) {
          if (x < 10) {
            outbuf[out_right] = '0' + x;
            ++out_right;
          } else {
            ::std::uint32_t q = (::std::uint32_t(x) * 205) >> 11;
            ::std::uint32_t r = ::std::uint32_t(x) - q * 10;
            outbuf[out_right] = '0' + q;
            outbuf[out_right + 1] = '0' + r;
            out_right += 2;
          }
        } else {
          if (x < 1000) {
            ::std::memcpy(outbuf + out_right, pre.num + (x << 2) + 1, 3);
            out_right += 3;
          } else {
            ::std::memcpy(outbuf + out_right, pre.num + (x << 2), 4);
            out_right += 4;
          }
        }
        ::std::memcpy(outbuf + out_right, buf + i + 4, 12 - i);
        out_right += 12 - i;
      }

      static struct Dummy {
        Dummy() { ::std::atexit(flush); }
      } dummy;
    }
  }

  struct ostream {
    template <typename... Args>
    ::tools::ostream& operator<<(Args&&... args) {
      ::tools::detail::ostream::wt(::std::forward<Args>(args)...);
      return *this;
    }
  };

  ::tools::ostream cout;
}


#line 6 "tests/fastio/integer.test.cpp"

using ll = long long;

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);

  int T;
  tools::cin >> T;
  for (int i = 0; i < T; ++i) {
    ll A, B;
    tools::cin >> A >> B;
    tools::cout << A + B << '\n';
  }

  return 0;
}

Test cases

Env Name Status Elapsed Memory
g++ all_max_00 :heavy_check_mark: AC 66 ms 4 MB
g++ all_zero_00 :heavy_check_mark: AC 15 ms 4 MB
g++ digit_random_00 :heavy_check_mark: AC 54 ms 4 MB
g++ digit_random_01 :heavy_check_mark: AC 56 ms 4 MB
g++ example_00 :heavy_check_mark: AC 5 ms 4 MB
g++ max_random_00 :heavy_check_mark: AC 68 ms 4 MB
g++ max_random_01 :heavy_check_mark: AC 70 ms 4 MB
g++ random_00 :heavy_check_mark: AC 30 ms 4 MB
g++ random_01 :heavy_check_mark: AC 34 ms 4 MB
Back to top page