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

#include <bits/stdc++.h>
using namespace std;

#define fast()                                                                 \\
  {                                                                            \\
    ios_base::sync_with_stdio(0);                                              \\
    cin.tie(0);                                                                \\
    cout.tie(0);                                                               \\
  }
#define o(a)                                                                   \\
  { cout << #a << ":" << (a) << " "; }
#define ov(a)                                                                  \\
  {                                                                            \\
    cout << "[";                                                               \\
    for (int i = 0; i < (a).size(); ++i) {                                     \\
      cout << i << ":" << a[i] << " ";                                         \\
      if (i % 10 == 9)                                                         \\
        cout << "\\n";                                                          \\
    }                                                                          \\
    cout << "]";                                                               \\
  }
#define ovv(a)                                                                 \\
  {                                                                            \\
    cout << "[";                                                               \\
    for (int i = 0; i < a.size(); ++i) {                                       \\
      for (int j = 0; j < a[i].size(); ++j) {                                  \\
        cout << "(" << i << "," << j << ")"                                    \\
             << ":" << a[i][j] << " ";                                         \\
      }                                                                        \\
      cout << "\\n";                                                            \\
    }                                                                          \\
    cout << "]";                                                               \\
  }
#define op(a)                                                                  \\
  {                                                                            \\
    cout << "[" << #a << ".fi:" << a.first;                                    \\
    cout << " " << #a << ".se:" << a.second << "]";                            \\
  }

#define ll long long
const int mod = 2019;
int main() {
  fast();
  string s;
  cin >> s;
  int n = s.length();
  vector<int> pow_10(n + 1);
  int t = 1;
  pow_10[0] = 1;
  for (int i = 1; i <= n; ++i) {
    pow_10[i] = (pow_10[i - 1] * 10) % mod;
  }
  vector<int> d(n + 1), tol(2020, 0);
  int rs = 0;
  d[n - 1] = s[n - 1] - '0';
  tol[d[n - 1]]++;
  tol[0]++;
  for (int i = n - 2; i >= 0; --i) {
    d[i] = (d[i + 1] + (s[i] - '0') * pow_10[n - i - 1]) % mod;
    rs += tol[d[i]];
    tol[d[i]]++;
  }
  // ov(pow_10)
  // ov(d)
  cout << rs;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define fast()                                                                 \\
  {                                                                            \\
    ios_base::sync_with_stdio(0);                                              \\
    cin.tie(0);                                                                \\
    cout.tie(0);                                                               \\
  }
#define o(a)                                                                   \\
  { cout << #a << ":" << (a) << " "; }
#define ov(a)                                                                  \\
  {                                                                            \\
    cout << "[";                                                               \\
    for (int i = 0; i < (a).size(); ++i) {                                     \\
      cout << i << ":" << a[i] << " ";                                         \\
      if (i % 10 == 9)                                                         \\
        cout << "\\n";                                                          \\
    }                                                                          \\
    cout << "]";                                                               \\
  }
#define ovv(a)                                                                 \\
  {                                                                            \\
    cout << "[";                                                               \\
    for (int i = 0; i < a.size(); ++i) {                                       \\
      for (int j = 0; j < a[i].size(); ++j) {                                  \\
        cout << "(" << i << "," << j << ")"                                    \\
             << ":" << a[i][j] << " ";                                         \\
      }                                                                        \\
      cout << "\\n";                                                            \\
    }                                                                          \\
    cout << "]";                                                               \\
  }
#define op(a)                                                                  \\
  {                                                                            \\
    cout << "[" << #a << ".fi:" << a.first;                                    \\
    cout << " " << #a << ".se:" << a.second << "]";                            \\
  }

#define ll long long
const int mod = 2019;
int main() {
  fast();
  string s;
  cin >> s;
  int n = s.length();
  vector<int> pow_10(n + 1);
  int t = 1;
  pow_10[0] = 1;
  for (int i = 1; i <= n; ++i) {
    pow_10[i] = (pow_10[i - 1] * 10) % mod;
  }
  vector<int> d(n + 1), tol(2010, 0);
  int rs = 0;
  d[n - 1] = s[n - 1] - '0';
  tol[0]++;
  for (int i = n - 2; i >= 0; --i) {
    d[i] = (d[i + 1] + (s[i] - '0') * pow_10[n - i - 1]) % mod;
    rs += tol[d[i]];
    tol[d[i]]++;
  }
  // ov(pow_10)
  // ov(d)
  cout << rs;
}