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

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

using ll = long long;
template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(), v.end()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define DEBUG_VLL(vec)                                                         \\
  for (int sz = 0; sz < int(vec.size()); sz++)                                 \\
    std::cerr << vec[sz] << (sz == vec.size() - 1 ? '\\n' : ' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  V<string> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vll aa(n, 0);
  for (int i = 0; i < n; i++) {
    int j = 0;
    while (j < a[i].size() && a[i][j] != '.') {
      aa[i] = aa[i] * 10LL + ll(a[i][j] - '0');
      j++;
    }
    j++;
    for (int jj = j; jj < j + 9; jj++) {
      if (jj >= int(a[i].size()))
        aa[i] *= 10LL;
      else
        aa[i] = aa[i] * 10LL + ll(a[i][jj] - '0');
    }
  }
  // DEBUG_VLL(aa)
  V<P<int, int>> a25(n, make_pair(0, 0));
  for (int i = 0; i < n; i++) {
    while (aa[i] % 2 == 0)
      a25[i].first++, aa[i] /= 2;
    while (aa[i] % 5 == 0)
      a25[i].second++, aa[i] /= 5;
  }

  sort(ALL(a25), [&](P<int, int> i, P<int, int> j) {
    if (i.first == j.first)
      return i.second > j.second;
    else
      return i.first > j.first;
  });

  ll ans = 0;
  V<V<int>> plot(50, V<int>(25, 0));
  for (int i = 0; i < n; i++) {
    int rem2 = max(0, 18 - a25[i].first), rem5 = max(18 - a25[i].second, 0);
    for (int i2 = rem2; i2 < 50; i2++) {
      for (int i5 = rem5; i5 < 25; i5++) {
        ans += ll(plot[i2][i5]);
      }
    }
    plot[a25[i].first][a25[i].second]++;
  }
  cout << ans << '\\n';
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

using ll = long long;
template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(), v.end()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define DEBUG_VLL(vec)                                                         \\
  for (int sz = 0; sz < int(vec.size()); sz++)                                 \\
    std::cerr << vec[sz] << (sz == vec.size() - 1 ? '\\n' : ' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

template <class T> class SegmentTree {
  // 0-indexed Segment Tree
  long long n;                 // 葉の数
  vector<T> data;              // データを格納する配列
  T def;                       // 初期値（単位元）
  function<T(T, T)> operation; // 区間クエリで使う処理
  function<T(T, T)> update;    // 点更新で使う処理

  // 区間 [a, b) に対する query !!!!!
  T _query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l)
      return def;
    if (a <= l && r <= b)
      return data[k]; // a,l,r,bの順で含まれる
    else {
      T c1 = _query(a, b, 2 * k + 1, l, (l + r) >> 1);
      T c2 = _query(a, b, 2 * k + 2, (l + r) >> 1, r);
      return operation(c1, c2);
    }
  }

public:
  // _n: 葉の要素の数, _def: 初期値（単位元）, _operation: クエリの関数,
  // _update: 更新用の関数
  SegmentTree(size_t _n, T _def, function<T(T, T)> _operation,
              function<T(T, T)> _update)
      : n(_n), def(_def), operation(_operation), update(_update) {
    n = 1;
    while (n < _n)
      n <<= 1;
    data = vector<T>(2 * n - 1, def);
  }

  void change(int i, T x) {
    i += n - 1;
    data[i] = update(data[i], x);
    while (i > 0) {
      i = (i - 1) >> 1;
      data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }

  // 区間 [a, b) に対する query !!!!!
  T query(int a, int b) { return _query(a, b, 0, 0, n); }

  T operator[](int i) { return data[i + n - 1]; }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  V<string> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vll aa(n, 0);
  for (int i = 0; i < n; i++) {
    int j = 0;
    while (j < a[i].size() && a[i][j] != '.') {
      aa[i] = aa[i] * 10LL + ll(a[i][j] - '0');
      j++;
    }
    j++;
    for (int jj = j; jj < j + 9; jj++) {
      if (jj >= int(a[i].size()))
        aa[i] *= 10LL;
      else
        aa[i] = aa[i] * 10LL + ll(a[i][jj] - '0');
    }
  }
  // DEBUG_VLL(aa)
  V<P<int, int>> a25(n, make_pair(0, 0));
  for (int i = 0; i < n; i++) {
    while (aa[i] % 2 == 0)
      a25[i].first++, aa[i] /= 2;
    while (aa[i] % 5 == 0)
      a25[i].second++, aa[i] /= 5;
  }

  sort(ALL(a25), [&](P<int, int> i, P<int, int> j) {
    if (i.first == j.first)
      return i.second > j.second;
    else
      return i.first > j.first;
  });

  ll ans = 0;
  V<V<int>> plot(50, V<int>(25, 0));
  for (int i = 0; i < n; i++) {
    int rem2 = 18 - a25[i].first, rem5 = 18 - a25[i].second;
    for (int i2 = rem2; i2 < 50; i2++) {
      for (int i5 = rem5; i5 < 25; i5++) {
        ans += ll(plot[i2][i5]);
      }
    }
    plot[a25[i].first][a25[i].second]++;
  }
  cout << ans << '\\n';
  return 0;
}