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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int, int> pint;
#define All(s) s.begin(), s.end()
#define rAll(s) s.rbegin(), s.rend()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// 問題文および制約はちゃんと確認しよう！
// サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
// とりあえずサンプルを読んでから解法を考えよう？
ostream &operator<<(ostream &os, const vector<lint> &a) {
  os << "[";
  rep(i, a.size()) {
    os << a[i];
    if (i < a.size() - 1)
      os << ",";
  }
  os << "]";
  return os;
}
vector<lint> cal(vector<lint> x) {
  int rank = 0;
  rep(i, 63) {
    if (rank >= x.size())
      break;
    REP(j, rank, x.size()) {
      if ((x[j] & (1L << i)))
        swap(x[rank], x[j]);
    }
    if (!(x[rank] & (1L << i)))
      continue;
    rep(j, x.size()) {
      if (j == rank)
        continue;
      if ((x[j] & (1L << i)))
        x[j] ^= x[rank];
    }
    rank++;
  }
  REP(i, rank, x.size()) { assert(x[i] == 0L); }
  /*rep(i,rank) REP(j,i+1,rank){
          assert((x[i]&x[j])==0L);
  }*/
  // x.resize(rank);
  // return x;
  vector<lint> ret;
  rep(i, rank) {
    // assert(x[i]>0L);
    ret.pb(x[i]);
  }
  return ret;
}
bool ng(lint y, vector<lint> x) {
  int rank = 0;
  rep(i, x.size()) {
    while (!(x[i] & (1L << rank)))
      rank++;
    if ((y & (1L << rank)) > 0L)
      y ^= x[i];
    rank++;
  }
  // cout<<y<<endl;
  if (y > 0L)
    return true;
  return false;
}
lint a[252];
string s;
int ca() {
  int n;
  cin >> n;
  rep(i, n) cin >> a[i];
  cin >> s;
  vector<lint> x, y;
  // if(s[n-1]=='1') return 1;
  int now = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '0') {
      x.pb(a[i]);
      x = cal(x);
      // cout<<x<<endl;
    } else {
      y.pb(a[i]);
      y = cal(y);
      rep(j, y.size()) {
        if (ng(y[j], x))
          return 1;
      }
    }
  }
  return 0;
}
int main() {
  int t;
  cin >> t;
  rep(i, t) cout << ca() << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int, int> pint;
#define All(s) s.begin(), s.end()
#define rAll(s) s.rbegin(), s.rend()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// 問題文および制約はちゃんと確認しよう！
// サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
// とりあえずサンプルを読んでから解法を考えよう？
ostream &operator<<(ostream &os, const vector<lint> &a) {
  os << "[";
  rep(i, a.size()) {
    os << a[i];
    if (i < a.size() - 1)
      os << ",";
  }
  os << "]";
  return os;
}
vector<lint> cal(vector<lint> x) {
  int rank = 0;
  rep(i, 63) {
    if (rank >= x.size())
      break;
    REP(j, rank, x.size()) {
      if ((x[j] & (1L << i)))
        swap(x[rank], x[j]);
    }
    if (!(x[rank] & (1L << i)))
      continue;
    rep(j, x.size()) {
      if (j == rank)
        continue;
      if ((x[j] & (1L << i)))
        x[j] ^= x[rank];
    }
    rank++;
  }
  REP(i, rank, x.size()) { assert(x[i] == 0L); }
  rep(i, rank) REP(j, i + 1, rank) { assert((x[i] & x[j]) == 0L); }
  // x.resize(rank);
  // return x;
  vector<lint> ret;
  rep(i, rank) {
    assert(x[i] > 0L);
    ret.pb(x[i]);
  }
  return ret;
}
bool ng(lint y, vector<lint> x) {
  // cout<<y<<' '<<x<<endl;
  lint f = 0L;
  rep(i, x.size()) {
    lint T = (y & x[i]);
    f |= T;
    if (T > 0L && T < x[i])
      return true;
  }
  if (f != y)
    return true;
  return false;
}
lint a[252];
string s;
int ca() {
  int n;
  cin >> n;
  rep(i, n) cin >> a[i];
  cin >> s;
  vector<lint> x, y;
  // if(s[n-1]=='1') return 1;
  int now = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '0') {
      x.pb(a[i]);
      x = cal(x);
      // cout<<x<<endl;
    } else {
      y.pb(a[i]);
      y = cal(y);
      rep(j, y.size()) {
        if (ng(y[j], x))
          return 1;
      }
    }
  }
  return 0;
}
int main() {
  int t;
  cin >> t;
  rep(i, t) cout << ca() << endl;
}