Problem p03765 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

template <class T, class U> constexpr bool chmin(T &a, const U b) {
  if (a <= b)
    return false;
  a = b;
  return true;
}
template <class T, class U> constexpr bool chmax(T &a, const U b) {
  if (a >= b)
    return false;
  a = b;
  return true;
}
#define bit(n, k) ((n >> k) & 1)

// デバッグ
template <class T> void Vout(vector<T> &V) {
  cout << "\nstart\n";
  const int sz = V.size();
  for (int i = 0; i < sz; i++) {
    cout << i << " " << V[i] << '\n';
  }
  cout << "end\n" << endl;
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

constexpr int MAX = 1 << 30;
constexpr ll INF = 1LL << 62;
constexpr int MOD = 1e9 + 7;
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, -1, 1};

//__builtin_popcount(S);
// #define int ll
// vector<vector<int>> data(3, vector<int>(4));
// vector.resize(a,vector<int>(b,-1));
// vector<vector<vector<要素の型>>> 変数名(要素数1,
// vector<vector<要素の型>>(要素数2, vector<要素の型>(要素数3, 初期値)));

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  string S, T;
  int Q;
  cin >> S >> T >> Q;
  int sz = S.size(), tz = T.size();
  vector<int> s(sz), t(tz);
  for (int i = 0; i < sz; i++) {
    int x;
    if (S[i] == 'A')
      x = 1;
    else
      x = 2;
    if (i == 0)
      s[i] = x;
    else
      s[i] = s[i - 1] + x;
  }
  for (int i = 0; i < sz; i++) {
    int x;
    if (T[i] == 'A')
      x = 1;
    else
      x = 2;
    if (i == 0)
      t[i] = x;
    else
      t[i] = t[i - 1] + x;
  }

  while (Q--) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    b--;
    c--;
    d--;
    int ss, tt;
    if (a == 0)
      ss = s[b];
    else
      ss = s[b] - s[a - 1];
    if (c == 0)
      tt = t[d];
    else
      tt = t[d] - t[c - 1];
    if (ss % 3 == tt % 3)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}

Fixed submission:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

template <class T, class U> constexpr bool chmin(T &a, const U b) {
  if (a <= b)
    return false;
  a = b;
  return true;
}
template <class T, class U> constexpr bool chmax(T &a, const U b) {
  if (a >= b)
    return false;
  a = b;
  return true;
}
#define bit(n, k) ((n >> k) & 1)

// デバッグ
template <class T> void Vout(vector<T> &V) {
  cout << "\nstart\n";
  const int sz = V.size();
  for (int i = 0; i < sz; i++) {
    cout << i << " " << V[i] << '\n';
  }
  cout << "end\n" << endl;
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

constexpr int MAX = 1 << 30;
constexpr ll INF = 1LL << 62;
constexpr int MOD = 1e9 + 7;
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, -1, 1};

//__builtin_popcount(S);
// #define int ll
// vector<vector<int>> data(3, vector<int>(4));
// vector.resize(a,vector<int>(b,-1));
// vector<vector<vector<要素の型>>> 変数名(要素数1,
// vector<vector<要素の型>>(要素数2, vector<要素の型>(要素数3, 初期値)));

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  string S, T;
  int Q;
  cin >> S >> T >> Q;
  int sz = S.size(), tz = T.size();
  vector<int> s(sz), t(tz);
  for (int i = 0; i < sz; i++) {
    int x;
    if (S[i] == 'A')
      x = 1;
    else
      x = 2;
    if (i == 0)
      s[i] = x;
    else
      s[i] = s[i - 1] + x;
  }
  for (int i = 0; i < tz; i++) {
    int x;
    if (T[i] == 'A')
      x = 1;
    else
      x = 2;
    if (i == 0)
      t[i] = x;
    else
      t[i] = t[i - 1] + x;
  }

  while (Q--) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    b--;
    c--;
    d--;
    int ss, tt;
    if (a == 0)
      ss = s[b];
    else
      ss = s[b] - s[a - 1];
    if (c == 0)
      tt = t[d];
    else
      tt = t[d] - t[c - 1];
    if (ss % 3 == tt % 3)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}