Problem p02608 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ss string
#define ll long long int
#define Endl endl
#define u_b upper_bound
#define rep(i, n) for (int i = 0; i < n; i++)
#define ld long double
#define tc                                                                     \\
  long long t;                                                                 \\
  cin >> t;                                                                    \\
  while (t--)
#define fr(i, a, b) for (long long int i = a; i <= b; i++)
#define E endl
#define FIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define V deque<ll> v;
#define aaste                                                                  \\
  long long int n;                                                             \\
  cin >> n;                                                                    \\
  long long int a[n];                                                          \\
  for (long long int i = 0; i < n; i++)                                        \\
    cin >> a[i];
const ll mod = 1000000007;
const ll MOD1 = (int)1e9 + 9;
const ll MOD2 = 998244353;
const ld pi = atan2(0, -1);
const ld eps = 1e-9;
const int N = 2e5 + 5;

const int MAXR = 1000005;
ll tests = 1;

using namespace std;
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }

  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
ll binarySearch(ll l, ll r, ll k) {
  if (r >= l) {
    ll mid = l + (r - l) / 2;
    if (mid * (mid + 1) == k)
      return 1;
    if (mid * (mid + 1) > k)
      return binarySearch(l, mid - 1, k);
    return binarySearch(mid + 1, r, k);
  }
  return 0;
}
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
void swap(ll *p1, ll *p2) {
  ll temp = *p1;
  *p1 = *p2;
  *p2 = temp;
}
ll cbratt(ll x) {
  ll l = 0, r = MAXR;
  while (l != r) {
    ll m = (l + r + 1) / 2;
    if (m * m * m > x)
      r = m - 1;
    else
      l = m;
  }
  return l;
}
int MaxSubArraySumReturn(int a[], int n) // negative thakle o kaaj korbe in O(n)
{

  int sum = 0, best = 0;
  for (ll i = 0; i < n; i++) {
    sum = max(a[i], a[i] + sum);
    best = max(best, sum);
  }
  return best;
}
ll totalDigits(ll n) {

  ll number_of_digits = 0;
  for (ll i = 1; i <= n; i *= 10)
    number_of_digits += (n - i + 1);

  return number_of_digits;
}

int main() {
#ifndef ONLINE_JUDGE
  {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
  }
#endif
  ll n;
  cin >> n;
  ll y = n;
  map<ll, ll> mp;
  n = sqrt(n);
  ll ctr = 0;
  for (ll x = 1; x <= n; x++) {
    for (ll y = 1; y <= n; y++) {
      for (ll z = 1; z <= n; z++) {
        ll twmp = (x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x);
        mp[twmp]++;
      }
    }
  }
  for (ll i = 1; i <= y; i++)
    cout << mp[i] << Endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ss string
#define ll long long int
#define Endl endl
#define u_b upper_bound
#define rep(i, n) for (int i = 0; i < n; i++)
#define ld long double
#define tc                                                                     \\
  long long t;                                                                 \\
  cin >> t;                                                                    \\
  while (t--)
#define fr(i, a, b) for (long long int i = a; i <= b; i++)
#define E endl
#define FIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define V deque<ll> v;
#define aaste                                                                  \\
  long long int n;                                                             \\
  cin >> n;                                                                    \\
  long long int a[n];                                                          \\
  for (long long int i = 0; i < n; i++)                                        \\
    cin >> a[i];
const ll mod = 1000000007;
const ll MOD1 = (int)1e9 + 9;
const ll MOD2 = 998244353;
const ld pi = atan2(0, -1);
const ld eps = 1e-9;
const int N = 2e5 + 5;

const int MAXR = 1000005;
ll tests = 1;

using namespace std;
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }

  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
ll binarySearch(ll l, ll r, ll k) {
  if (r >= l) {
    ll mid = l + (r - l) / 2;
    if (mid * (mid + 1) == k)
      return 1;
    if (mid * (mid + 1) > k)
      return binarySearch(l, mid - 1, k);
    return binarySearch(mid + 1, r, k);
  }
  return 0;
}
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
void swap(ll *p1, ll *p2) {
  ll temp = *p1;
  *p1 = *p2;
  *p2 = temp;
}
ll cbratt(ll x) {
  ll l = 0, r = MAXR;
  while (l != r) {
    ll m = (l + r + 1) / 2;
    if (m * m * m > x)
      r = m - 1;
    else
      l = m;
  }
  return l;
}
int MaxSubArraySumReturn(int a[], int n) // negative thakle o kaaj korbe in O(n)
{

  int sum = 0, best = 0;
  for (ll i = 0; i < n; i++) {
    sum = max(a[i], a[i] + sum);
    best = max(best, sum);
  }
  return best;
}
ll totalDigits(ll n) {

  ll number_of_digits = 0;
  for (ll i = 1; i <= n; i *= 10)
    number_of_digits += (n - i + 1);

  return number_of_digits;
}

int main() {
#ifndef ONLINE_JUDGE
  {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
  }
#endif
  ll n;
  cin >> n;

  for (ll i = 1; i <= n; i++) {
    ll ctr = 0;
    for (ll x = 1; x <= sqrt(i); x++) {
      for (ll y = 1; y <= sqrt(i); y++) {
        for (ll z = 1; z <= sqrt(i); z++) {
          ll twmp = (x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x);
          if (twmp == i)
            ctr++;
        }
      }
    }
    cout << ctr << endl;
  }
}