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

#include <bits/stdc++.h>
using namespace std;
#define Next(i, x) for (int i = head[x]; i; i = e[i].next)
#define rep(i, s, t) for (int i = (s); i <= (t); ++i)
#define drep(i, s, t) for (int i = (t); i >= (s); --i)
#define int long long
int gi() {
  char cc = getchar();
  int cn = 0, flus = 1;
  while (cc < '0' || cc > '9') {
    if (cc == '-')
      flus = -flus;
    cc = getchar();
  }
  while (cc >= '0' && cc <= '9')
    cn = cn * 10 + cc - '0', cc = getchar();
  return cn * flus;
}
const int N = 500 + 5;
const int M = 100 + 5;
int T, n, A[N], flag, b[M];
char s[N];
void solve(int l, int r, int type) {
  if (type == 0) {
    rep(j, l, r) {
      int x = A[j];
      for (int i = 60; i >= 0; --i) {
        int u = (1ll << i);
        if (u & x)
          x ^= b[i];
      }
      if (x)
        flag = 1;
    }
  } else {
    rep(j, l, r) {
      int x = A[j];
      for (int i = 60; i >= 0; --i) {
        int u = (1ll << i);
        if (u & x) {
          if (!b[i])
            b[i] = x, x = 0;
          else
            x ^= b[i];
        }
      }
    }
  }
}
signed main() {
  T = gi();
  while (T--) {
    n = gi();
    rep(i, 1, n) A[i] = gi();
    scanf("%s", s + 1);
    s[0] = '5';
    int lst = n;
    flag = 0;
    for (int i = n; i >= 1; --i) {
      if (s[i] != s[i - 1]) {
        if (s[i] == '0')
          solve(i, lst, 1);
        else
          solve(i, lst, 0);
        lst = i - 1;
      }
    }
    if (flag)
      puts("1");
    else
      puts("0");
    rep(i, 0, 65) b[i] = 0;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define Next(i, x) for (register int i = head[x]; i; i = e[i].next)
#define rep(i, s, t) for (register int i = (s); i <= (t); ++i)
#define drep(i, s, t) for (register int i = (t); i >= (s); --i)
#define re register
#define int long long
int gi() {
  char cc = getchar();
  int cn = 0, flus = 1;
  while (cc < '0' || cc > '9') {
    if (cc == '-')
      flus = -flus;
    cc = getchar();
  }
  while (cc >= '0' && cc <= '9')
    cn = cn * 10 + cc - '0', cc = getchar();
  return cn * flus;
}
const int N = 300 + 5;
const int M = 60 + 5;
int T, n, A[N], b[M], bb[M], st[N], top;
char s[N];
void solve(int l, int r, int type) {
  if (type == 0) {
    rep(j, l, r) {
      int x = A[j];
      for (re int i = 61; i >= 0; --i) {
        int u = (1ll << i);
        if (u & x) {
          if (!bb[i])
            bb[i] = x, x = 0;
          else
            x ^= bb[i];
        }
      }
    }
    for (re int i = 61; i >= 0; --i) {
      if (!b[i])
        continue;
      int x = b[i];
      for (re int j = 61; j >= 0; --j) {
        int u = (1ll << j);
        if (u & x)
          x ^= bb[j];
      }
      if (!x)
        b[i] = 0;
    }
    rep(i, 0, 61) bb[i] = 0;
  } else {
    rep(j, l, r) {
      int x = A[j];
      for (re int i = 61; i >= 0; --i) {
        int u = (1ll << i);
        if (u & x) {
          if (!b[i])
            b[i] = x, x = 0;
          else
            x ^= b[i];
        }
      }
    }
  }
}
signed main() {
  T = gi();
  while (T--) {
    n = gi();
    rep(i, 1, n) A[i] = gi();
    scanf("%s", s + 1);
    s[n + 1] = '5';
    int bef = 1;
    rep(i, 1, n) {
      st[++top] = i;
      if (s[i] != s[i + 1]) {
        if (s[i] == '0')
          solve(bef, i, 0);
        else
          solve(bef, i, 1);
        bef = i + 1;
      }
    }
    int flag = 0;
    rep(i, 0, 61) if (b[i]) flag = 1;
    if (flag)
      puts("1");
    else
      puts("0");
    rep(i, 0, 61) b[i] = 0;
  }
  return 0;
}