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

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_poizcy.hpp>
typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define clr(a, h) memset(a, (h), sizeof(a))
#define mem(a, h) memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a, b) (((a % MOD) * (b % MOD)) % MOD)
#define forg(i, b, e, c) for (ll i = (ll)b; i < (ll)e; i += c)
#define forr(i, b, e) for (ll i = b; i < e; i++)

using namespace std;
// using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll> ii;
typedef pair<double, double> iidb;
typedef pair<ll, ii> iii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<ll> vll;
// typedef
// tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update>
// ordered_set;
const ll INF = 1e9;
const double PI = acos(-1);
const ll MOD = 1e9 + 7;
#define initseg ll new_nodo = (nodo * 2), mid = (iz + der) / 2;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define tam 400
#define offset 200
int bit2d[tam + 20][tam + 20];
ll tot = 0;
void update(int posi, int posj) {
  if (posi < 0 || posj < 0) {
    //<<"filo";
    return;
  }
  for (int i = posi; i < tam; i += i & (-i)) {
    for (int j = posj; j < tam; j += j & (-j)) {
      bit2d[i][j]++;
    }
  }
  //<<"termino";
}
int query(int posi, int posj) {
  if (posi < 0 || posj < 0)
    assert(false);
  int rtot = 0;
  for (int i = posi; i > 0; i -= i & (-i)) {
    for (int j = posj; j > 0; j -= j & (-j)) {
      rtot += bit2d[i][j];
    }
  }
  return rtot;
}
void go(string txt) {

  ll valor = 0;
  bool valid = 0;
  int pos = 0;
  forr(i, 0, txt.size()) {
    if (txt[i] == '.') {
      valid = 1;
      continue;
    }
    if (valid)
      pos++;
    valor *= 10;
    valor += (txt[i] - '0');
  }
  //<<valor<<" ";
  int c2, c5;
  c2 = c5 = 0;
  while (valor % 2 == 0)
    valor /= 2, c2++;
  while (valor % 5 == 0)
    valor /= 5, c5++;
  //<<c2<<" "<<c5<<endl;
  int cant2 = c2 - pos, cant5 = c5 - pos;
  //<<cant2<<" "<<cant5<<endl;
  tot += query(tam - 1, tam - 1);
  //<<tot<<endl;
  tot -= query(offset - cant2 - 1, tam - 1);
  //<<tot<<endl;
  tot -= query(tam - 1, offset - cant5 - 1) -
         query(offset - cant2 - 1, offset - cant5 - 1);
  //<<tot<<endl;
  //<<query(tam-1,tam-1)<<"
  //"<<(query(offset-cant2,tam-1)+query(tam-1,offset-cant5)-query(offset-cant2,offset-cant5))<<endl;
  //<<tot<<" "<<cant2<<" "<<cant5<<endl;
  update(offset + cant2, offset + cant5);
  //<<"cagada\\n";
}
int main() {
  int n;
  cin >> n;
  string num;
  forr(i, 0, n) {
    cin >> num;
    go(num);
  }
  cout << tot << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_poizcy.hpp>
typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define clr(a, h) memset(a, (h), sizeof(a))
#define mem(a, h) memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a, b) (((a % MOD) * (b % MOD)) % MOD)
#define forg(i, b, e, c) for (ll i = (ll)b; i < (ll)e; i += c)
#define forr(i, b, e) for (ll i = b; i < e; i++)

using namespace std;
// using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll> ii;
typedef pair<double, double> iidb;
typedef pair<ll, ii> iii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<ll> vll;
// typedef
// tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update>
// ordered_set;
const ll INF = 1e9;
const double PI = acos(-1);
const ll MOD = 1e9 + 7;
#define initseg ll new_nodo = (nodo * 2), mid = (iz + der) / 2;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define tam 200
#define offset 80
int bit2d[tam + 20][tam + 20];
ll tot = 0;
int update(int posi, int posj) {
  for (int i = posi; i < tam; i += i & (-i)) {
    for (int j = posj; j < tam; j += j & (-j)) {
      bit2d[i][j]++;
    }
  }
}
int query(int posi, int posj) {
  int tot = 0;
  for (int i = posi; i > 0; i -= i & (-i)) {
    for (int j = posj; j > 0; j -= j & (-j)) {
      tot += bit2d[i][j];
    }
  }
  return tot;
}
void go(string txt) {

  ll valor = 0;
  bool valid = 0;
  int pos = 0;
  forr(i, 0, txt.size()) {
    if (txt[i] == '.') {
      valid = 1;
      continue;
    }
    if (valid)
      pos++;
    valor *= 10;
    valor += (txt[i] - '0');
  }
  // cout<<valor<<" ";
  int c2, c5;
  c2 = c5 = 0;
  while (valor % 2 == 0)
    valor /= 2, c2++;
  while (valor % 5 == 0)
    valor /= 5, c5++;
  // cout<<c2<<" "<<c5<<endl;
  int cant2 = c2 - pos, cant5 = c5 - pos;

  tot +=
      query(tam - 1, tam - 1) -
      (query(offset - cant2 - 1, tam - 1) + query(tam - 1, offset - cant5 - 1) -
       query(offset - cant2 - 1, offset - cant5 - 1));
  // cout<<query(tam-1,tam-1)<<"
  // "<<(query(offset-cant2,tam-1)+query(tam-1,offset-cant5)-query(offset-cant2,offset-cant5))<<endl;
  // cout<<tot<<" "<<cant2<<" "<<cant5<<endl;
  update(offset + cant2, offset + cant5);
}
int main() {
  int n;
  cin >> n;
  string num;
  forr(i, 0, n) {
    cin >> num;
    go(num);
  }
  cout << tot << endl;
}