Problem p02608 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using ll = long long;
using str = string;
using vl = vector<ll>;
using vs = vector<str>;
using listl = list<ll>;

#define min(A, B) min(static_cast<ll>(A), static_cast<ll>(B))
#define max(A, B) max(static_cast<ll>(A), static_cast<ll>(B))
#define all(x) (x).begin(), (x).end()
#define mp make_pair

#define _rep(i, m) for (ll i = 0, i_max = m; i < i_max; i++)
#define _erep(i, m) for (ll i = 0, i_max = m; i <= i_max; i++)
#define _nrep(i, b, m) for (ll i = b, i_max = m; i < i_max; i++)
#define _enrep(i, b, m) for (ll i = b, i_max = m; i <= i_max; i++)
#define _brep(i, m) for (ll i = m; i >= 0; i--)
#define _ebrep(i, b, e) for (ll i = b; i >= e; i--)

#define rep(m) _rep(i, m)
#define erep(m) _erep(i, m)
#define nrep(b, m) _nrep(i, b, m)
#define enrep(b, m) _enrep(i, b, m)
#define brep(m) _brep(i, m)
#define ebrep(b, e) _ebrep(i, b, e)

// modint: mod 計算を int を扱うように扱える構造体
template <int MOD> struct Fp {
  ll val;
  constexpr Fp(ll v = 0) noexcept : val(v % MOD) {
    if (val < 0)
      val += MOD;
  }
  constexpr int getmod() { return MOD; }
  constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
  constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
  constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
  constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
  constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
  constexpr Fp &operator+=(const Fp &r) noexcept {
    val += r.val;
    if (val >= MOD)
      val -= MOD;
    return *this;
  }
  constexpr Fp &operator-=(const Fp &r) noexcept {
    val -= r.val;
    if (val < 0)
      val += MOD;
    return *this;
  }
  constexpr Fp &operator*=(const Fp &r) noexcept {
    val = val * r.val % MOD;
    return *this;
  }
  constexpr Fp &operator/=(const Fp &r) noexcept {
    ll a = r.val, b = MOD, u = 1, v = 0;
    while (b) {
      ll t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    val = val * u % MOD;
    if (val < 0)
      val += MOD;
    return *this;
  }
  constexpr bool operator==(const Fp &r) const noexcept {
    return this->val == r.val;
  }
  constexpr bool operator!=(const Fp &r) const noexcept {
    return this->val != r.val;
  }
  friend ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept {
    return os << x.val;
  }
  friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, ll n) noexcept {
    if (n == 0)
      return 1;
    auto t = modpow(a, n / 2);
    t = t * t;
    if (n & 1)
      t = t * a;
    return t;
  }
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void in(ll &I) { cin >> I; }

void in(vl &I) {
  for (auto &i : I) {
    cin >> i;
  }
}

void in(vs &I) {
  for (auto &i : I) {
    cin >> i;
  }
}

void in(listl &I) {
  for (auto &i : I) {
    cin >> i;
  }
}

void in(str &s) { cin >> s; }

void out(ll O) { cout << O; }

void out(vl &O) {
  for (auto &o : O) {
    cout << o << endl;
  }
}

void rout(bool b, str True, str False) {
  if (b)
    cout << True.c_str();
  else
    cout << False.c_str();
}

int main() {
  ll N;
  cin >> N;

  vl ans(N, 0);

  _nrep(x, 1, sqrt(N)) {
    _nrep(y, 1, sqrt(N)) {
      _nrep(z, 1, sqrt(N)) {
        ll n = x * x + y * y + z * z + x * y + y * z + z * x;
        if (n <= N)
          ans[n - 1]++;
      }
    }
  }

  out(ans);

  return 0;
}


Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using ll = long long;
using str = string;
using vl = vector<ll>;
using vs = vector<str>;
using listl = list<ll>;

#define min(A, B) min(static_cast<ll>(A), static_cast<ll>(B))
#define max(A, B) max(static_cast<ll>(A), static_cast<ll>(B))
#define all(x) (x).begin(), (x).end()
#define mp make_pair

#define _rep(i, m) for (ll i = 0, i_max = m; i < i_max; i++)
#define _erep(i, m) for (ll i = 0, i_max = m; i <= i_max; i++)
#define _nrep(i, b, m) for (ll i = b, i_max = m; i < i_max; i++)
#define _enrep(i, b, m) for (ll i = b, i_max = m; i <= i_max; i++)
#define _brep(i, m) for (ll i = m; i >= 0; i--)
#define _ebrep(i, b, e) for (ll i = b; i >= e; i--)

#define rep(m) _rep(i, m)
#define erep(m) _erep(i, m)
#define nrep(b, m) _nrep(i, b, m)
#define enrep(b, m) _enrep(i, b, m)
#define brep(m) _brep(i, m)
#define ebrep(b, e) _ebrep(i, b, e)

// modint: mod 計算を int を扱うように扱える構造体
template <int MOD> struct Fp {
  ll val;
  constexpr Fp(ll v = 0) noexcept : val(v % MOD) {
    if (val < 0)
      val += MOD;
  }
  constexpr int getmod() { return MOD; }
  constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
  constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
  constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
  constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
  constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
  constexpr Fp &operator+=(const Fp &r) noexcept {
    val += r.val;
    if (val >= MOD)
      val -= MOD;
    return *this;
  }
  constexpr Fp &operator-=(const Fp &r) noexcept {
    val -= r.val;
    if (val < 0)
      val += MOD;
    return *this;
  }
  constexpr Fp &operator*=(const Fp &r) noexcept {
    val = val * r.val % MOD;
    return *this;
  }
  constexpr Fp &operator/=(const Fp &r) noexcept {
    ll a = r.val, b = MOD, u = 1, v = 0;
    while (b) {
      ll t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    val = val * u % MOD;
    if (val < 0)
      val += MOD;
    return *this;
  }
  constexpr bool operator==(const Fp &r) const noexcept {
    return this->val == r.val;
  }
  constexpr bool operator!=(const Fp &r) const noexcept {
    return this->val != r.val;
  }
  friend ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept {
    return os << x.val;
  }
  friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, ll n) noexcept {
    if (n == 0)
      return 1;
    auto t = modpow(a, n / 2);
    t = t * t;
    if (n & 1)
      t = t * a;
    return t;
  }
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void in(ll &I) { cin >> I; }

void in(vl &I) {
  for (auto &i : I) {
    cin >> i;
  }
}

void in(vs &I) {
  for (auto &i : I) {
    cin >> i;
  }
}

void in(listl &I) {
  for (auto &i : I) {
    cin >> i;
  }
}

void in(str &s) { cin >> s; }

void out(ll O) { cout << O; }

void out(vl &O) {
  for (auto &o : O) {
    cout << o << endl;
  }
}

void rout(bool b, str True, str False) {
  if (b)
    cout << True.c_str();
  else
    cout << False.c_str();
}

int main() {
  ll N;
  cin >> N;

  vl ans(N, 0);

  _rep(x, sqrt(N)) {
    _rep(y, sqrt(N)) {
      _rep(z, sqrt(N)) {
        ll n = x * x + y * y + z * z + x * y + y * z + z * x;
        if (n < N)
          ans[n - 1]++;
      }
    }
  }

  out(ans);

  return 0;
}