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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << '[';
  string sep = "";
  for (const auto &x : v)
    os << sep << x, sep = ", ";
  return os << ']';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
template <typename A> ostream &operator<<(ostream &os, const set<A> &s) {
  os << '{';
  string sep = "";
  for (const auto &x : s)
    os << sep << x, sep = ", ";
  return os << '}';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const map<A, B> &m) {
  os << '{';
  string sep = "";
  for (const auto &x : m)
    os << sep << x.first << " -> " << x.second, sep = ", ";
  return os << '}';
}

#ifdef MY_DEBUG_FLAG
void debug() { cerr << '\\n'; }
template <typename Ini, typename... Fim> void debug(Ini I, Fim... F) {
  cerr << " " << I;
  debug(F...);
}
#define db(...) cerr << "DEBUG (" << #__VA_ARGS__ << ") ==", debug(__VA_ARGS__)
#else
#define db(...)
#endif

#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define fast                                                                   \\
  ios_base::sync_with_stdio(false), cout.tie(nullptr), cin.tie(nullptr)
#define sz(a) ((int)(a).size())
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define dec(i, n, a) for (int i = (n); i >= (a); i--)
#define clr(a, v) memset(a, v, sizeof(a))
#define all(a) (a).begin(), (a).end()

constexpr int inf = 0x3f3f3f3f;
constexpr int maxn = 1e5 + 10;
constexpr int mod = 1000000007;

// int bit[30][30];
int pot[20][20];

// void upd(int x, int v, int k) {
// 	for(x++; x < 27; x += x&-x)
// 		bit[x][k] += v;
// }

// int query(int x, int k) {
// 	int ans = 0;
// 	for(x++; x > 0; x -= x&-x)
// 		ans += bit[x][k];
// 	return ans;
// }

int main() {
  fast;
  int n;
  cin >> n;
  ll ans = 0;
  rep(i, 0, n) {
    string massa;
    cin >> massa;
    int t = sz(massa);

    int antes = 0, dec = 0;
    bool ok = 0;
    rep(j, 0, t) {
      if (massa[j] == '.')
        ok = 1;
      else if (ok)
        dec++;
      else
        antes++;
    }

    ll a = 0;

    rep(j, 0, t) if (massa[j] != '.') a *= 10ll, a += massa[j] - '0';

    rep(j, dec, 9) a *= 10ll;

    int p2 = 0, p5 = 0;
    while (a % 2 == 0)
      a /= 2ll, p2++;
    while (a % 5 == 0)
      a /= 5ll, p5++;

    p2 = min(p2, 18);
    p5 = min(p5, 18);

    rep(j, 18 - p2, 19) rep(x, 18 - p5, 19) ans += pot[j][x];
    // ans += query(18, j) - query(18-p5,j);

    pot[p2][p5]++;
    // upd(p5, 1, p2);
  }

  cout << ans << '\\n';
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << '[';
  string sep = "";
  for (const auto &x : v)
    os << sep << x, sep = ", ";
  return os << ']';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
template <typename A> ostream &operator<<(ostream &os, const set<A> &s) {
  os << '{';
  string sep = "";
  for (const auto &x : s)
    os << sep << x, sep = ", ";
  return os << '}';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const map<A, B> &m) {
  os << '{';
  string sep = "";
  for (const auto &x : m)
    os << sep << x.first << " -> " << x.second, sep = ", ";
  return os << '}';
}

#ifdef MY_DEBUG_FLAG
void debug() { cerr << '\\n'; }
template <typename Ini, typename... Fim> void debug(Ini I, Fim... F) {
  cerr << " " << I;
  debug(F...);
}
#define db(...) cerr << "DEBUG (" << #__VA_ARGS__ << ") ==", debug(__VA_ARGS__)
#else
#define db(...)
#endif

#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define fast                                                                   \\
  ios_base::sync_with_stdio(false), cout.tie(nullptr), cin.tie(nullptr)
#define sz(a) ((int)(a).size())
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define dec(i, n, a) for (int i = (n); i >= (a); i--)
#define clr(a, v) memset(a, v, sizeof(a))
#define all(a) (a).begin(), (a).end()

constexpr int inf = 0x3f3f3f3f;
constexpr int maxn = 1e5 + 10;
constexpr int mod = 1000000007;

int pot[10][10];

int main() {
  fast;
  int n;
  cin >> n;
  ll ans = 0;
  rep(i, 0, n) {
    string massa;
    cin >> massa;
    int t = sz(massa);
    bool ok = 0;
    rep(j, 0, t) if (massa[j] == '.') ok = 1;
    if (ok)
      while (massa.back() == '0' && t >= 1)
        t--, massa.pop_back();
    if (t > 9)
      continue;

    ll a = 0;
    bool have = 0;
    int cnt = 0, p2 = 0, p5 = 0;

    rep(j, 0, t) {
      if (massa[j] == '.') {
        have = 1;
        continue;
      }
      a *= 10, a += massa[j] - '0';
      if (have)
        cnt++;
    }

    assert(cnt < 4);
    rep(j, cnt, 4) a *= 10;

    while (a % 2 == 0)
      a /= 2, p2++;
    while (a % 5 == 0)
      a /= 5, p5++;

    p2 = min(p2, 8);
    p5 = min(p5, 8);

    rep(x, 8 - p2, 9) {
      rep(y, 8 - p5, 9) { ans += pot[x][y]; }
    }

    pot[p2][p5]++;
  }

  cout << ans << '\\n';
}