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

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll, ll> P;
typedef pair<int, int> pii;
typedef vector<P> vpl;
typedef tuple<ll, ll, ll> tapu;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1 << 30;
const ll linf = 1LL << 62;
const int MAX = 5020000;
ll dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};
ll dx[8] = {0, 0, 1, -1, 1, -1, -1, 1};
const double pi = acos(-1);
const double eps = 1e-7;
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}
template <typename T> inline void print(T &a) {
  rep(i, a.size()) cout << a[i] << " ";
  cout << "\\n";
}
template <typename T1, typename T2> inline void print2(T1 a, T2 b) {
  cout << a << " " << b << "\\n";
}
template <typename T1, typename T2, typename T3>
inline void print3(T1 a, T2 b, T3 c) {
  cout << a << " " << b << " " << c << "\\n";
}
ll pcount(ll x) { return __builtin_popcountll(x); }
const int mod = 1e9 + 7;
// const int mod = 998244353;

struct sum2D {
  vector<vector<ll>> sum;
  ll n, m;

  sum2D(vector<vector<ll>> &a) {
    n = a.size();
    m = a[0].size();
    sum.resize(n + 1);
    rep(i, n + 1) sum[i].resize(m + 1, 0);
    rep(i, n) rep(j, m) sum[i + 1][j + 1] = a[i][j];
    rep(i, n) rep(j, m + 1) sum[i + 1][j] += sum[i][j];
    rep(j, m) rep(i, n + 1) sum[i][j + 1] += sum[i][j];
  }

  ll get(int y1, int x1, int y2, int x2) {
    y2++;
    x2++;
    return sum[y2][x2] - sum[y2][x1] - sum[y1][x2] + sum[y1][x1];
  }
};

vvl cnt(20, vl(20, 0));

int main() {
  ll n;
  cin >> n;
  vd a(n);
  rep(i, n) cin >> a[i];
  vl b(n);
  vpl v(n);
  rep(i, n) {
    a[i] *= 1000000000;
    b[i] = (ll)(a[i] + 0.1);
    int two = 0, five = 0;
    while (b[i] % 2 == 0)
      two++, b[i] /= 2;
    while (b[i] % 5 == 0)
      five++, b[i] /= 5;
    chmin(two, 18);
    chmin(five, 18);
    v[i] = {two, five};
    cnt[two][five]++;
  }
  sum2D sum(cnt);
  ll ans = 0;
  ll as2 = 0;
  rep(i, n) {
    // print2(v[i].first, v[i].second);
    ans += sum.get(18 - v[i].first, 18 - v[i].second, 19, 19);
    if (v[i].first >= 9 && v[i].second >= 9)
      ans--, as2--;
    REP(j, 18 - v[i].first, 19) {
      REP(k, 18 - v[i].second, 19) as2 += cnt[j][k];
    }
  }
  ans /= 2;
  as2 /= 2;
  // if(ans != as2) puts("NO");
  cout << as2 << "\\n";
}

Error: 0

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll, ll> P;
typedef pair<int, int> pii;
typedef vector<P> vpl;
typedef tuple<ll, ll, ll> tapu;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1 << 30;
const ll linf = 1LL << 62;
const int MAX = 5020000;
ll dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};
ll dx[8] = {0, 0, 1, -1, 1, -1, -1, 1};
const double pi = acos(-1);
const double eps = 1e-7;
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}
template <typename T> inline void print(T &a) {
  rep(i, a.size()) cout << a[i] << " ";
  cout << "\\n";
}
template <typename T1, typename T2> inline void print2(T1 a, T2 b) {
  cout << a << " " << b << "\\n";
}
template <typename T1, typename T2, typename T3>
inline void print3(T1 a, T2 b, T3 c) {
  cout << a << " " << b << " " << c << "\\n";
}
ll pcount(ll x) { return __builtin_popcountll(x); }
const int mod = 1e9 + 7;
// const int mod = 998244353;

struct sum2D {
  vector<vector<ll>> sum;
  ll n, m;

  sum2D(vector<vector<ll>> &a) {
    n = a.size();
    m = a[0].size();
    sum.resize(n + 1);
    rep(i, n + 1) sum[i].resize(m + 1, 0);
    rep(i, n) rep(j, m) sum[i + 1][j + 1] = a[i][j];
    rep(i, n) rep(j, m + 1) sum[i + 1][j] += sum[i][j];
    rep(j, m) rep(i, n + 1) sum[i][j + 1] += sum[i][j];
  }

  ll get(int y1, int x1, int y2, int x2) {
    y2++;
    x2++;
    return sum[y2][x2] - sum[y2][x1] - sum[y1][x2] + sum[y1][x1];
  }
};

vvl cnt(20, vl(20, 0));

int main() {
  ll n;
  cin >> n;
  vd a(n);
  rep(i, n) cin >> a[i];
  vl b(n);
  vpl v(n);
  rep(i, n) {
    a[i] *= 1e9;
    b[i] = (ll)a[i];
    ll two = 0, five = 0;
    while (b[i] % 2 == 0)
      two++, b[i] /= 2;
    while (b[i] % 5 == 0)
      five++, b[i] /= 5;
    v[i] = {two, five};
    cnt[two][five]++;
  }
  sum2D sum(cnt);
  ll ans = 0;
  rep(i, n) {
    ans += sum.get(18 - v[i].first, 18 - v[i].second, 19, 19);
    if (v[i].first >= 9 && v[i].second >= 9)
      ans--;
  }
  cout << ans / 2 << "\\n";
}