alexjercan/bugnet huggingface dataset:
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for (int i = 0; i < N; i++)

int main() {
  int T;
  cin >> T;
  while (T--) {
    int N;
    vector<i64> A;
    string S;

    cin >> N;
    A.resize(N);
    rep(i, N) cin >> A[i];
    cin >> S;

    reverse(A.begin(), A.end());
    reverse(S.begin(), S.end());

    vector<i64> st(1, 0);
    st.reserve(100000);

    rep(i, N) {
      if (st.size() == 0)
        break;

      i64 x = A[i];
      for (const i64 &v : st) {
        x = min(x, x ^ v);
      }

      if (x != 0) {
        if (S[i] == '1')
          st.clear();
        else
          st.emplace_back(x);
      }
    }

    if (st.size() == 0)
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for (int i = 0; i < N; i++)

bool contain(const vector<i64> &vec, const i64 &x) {
  for (const auto &v : vec) {
    if (v == x)
      return true;
  }

  return false;
}

int main() {
  int T;
  cin >> T;
  while (T--) {
    int N;
    vector<i64> A;
    string S;

    cin >> N;
    A.resize(N);
    rep(i, N) cin >> A[i];
    cin >> S;

    reverse(A.begin(), A.end());
    reverse(S.begin(), S.end());

    vector<i64> st(1, 0);
    st.reserve(100000);

    rep(i, N) {
      if (st.size() == 0)
        break;

      if (S[i] == '0') {
        if (contain(st, A[i]))
          continue;
        size_t sz = st.size();
        for (int k = 0; k < sz; k++) {
          st.emplace_back(st[k] ^ A[i]);
        }
      } else {
        if (!contain(st, A[i]))
          st.clear();
      }
    }

    if (st.size() == 0)
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
}
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

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

void solve() {
  int n;
  cin >> n;
  vector<ll> an(n);
  for (int i = 0; i < n; ++i)
    cin >> an[i];
  string s;
  cin >> s;
  vector<ll> bases;
  for (int i = n - 1; i >= 0; --i) {
    ll x = an[i];
    for (ll base : bases) {
      x = min(x, x ^ base);
    }
    if (s[i] == '0')
      bases.push_back(x);
    else if (x) {
      cout << 1 << endl;
      return;
    }
  }
  cout << 0 << endl;
  return;
}

int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i)
    solve();
}

Error: TLE

Fixed submission:

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

void solve() {
  int n;
  cin >> n;
  vector<ll> an(n);
  for (int i = 0; i < n; ++i)
    cin >> an[i];
  string s;
  cin >> s;
  set<ll> st;
  st.insert(0);
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == '0') {
      set<ll> st2;
      for (ll x : st) {
        st2.insert(x);
        st2.insert(x ^ an[i]);
      }
      st = st2;
    } else {
      if (st.find(an[i]) == st.end()) {
        cout << 1 << endl;
        return;
      }
    }
  }
  cout << 0 << endl;
  return;
}

int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i)
    solve();
}
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
typedef long long ll;
ll q, n, a[200], b[61];
string s;
ll ins(ll x) {
  for (ll i = 60; i >= 0; i--) {
    if (((x >> i) & 1) == 1) {
      if (b[i] == 0) {
        b[i] = x;
        return 1;
      }
      x ^= b[i];
    }
  }
  return 0;
}
int main(void) {
  cin >> q;
  while (q--) {
    ll ok = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
      cin >> a[i];
    cin >> s;
    for (int i = 0; i <= 60; i++)
      b[i] = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (ins(a[i]) == 1 && s[i] == '1') {
        cout << 1 << endl;
        ok = 1;
        break;
      }
    }
    if (ok == 0)
      cout << 0 << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
ll q, n, a[200], b, c;
string s;
vector<ll> v;
map<ll, ll> mp, mp2;
int main(void) {
  cin >> q;
  while (q--) {
    cin >> n;
    mp.clear();
    mp2.clear();
    for (int i = 0; i < n; i++) {
      cin >> a[n - i - 1];
    }
    cin >> s;
    // cout<<s<<endl;
    reverse(s.begin(), s.end());
    if (s[0] == '1') {
      cout << 1 << endl;
      continue;
    }
    mp[0] = 1;
    for (int i = 0; i < n; i++) {
      if (s[i] == '0') {
        mp2 = mp;
        for (auto x : mp)
          mp2[x.first ^ a[i]] = 1;
      } else {
        for (auto x : mp) {
          if (mp.count(a[i]) == 1 && mp.count(a[i] ^ x.first) == 1) {
            mp2[a[i]] = 1;
            mp2[a[i] ^ x.first] = 1;
          }
        }
      }
      mp = mp2;
      mp2.clear();
    }
    if (mp[0] == 1)
      cout << 0 << endl;
    else
      cout << 1 << endl;
    // cout<<mp[0]<<endl;
  }
}
Problem p02651 (C++) — buggy submission, verdict: Runtime Error

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

#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;

void insert(vector<int> &basis, int mask) {
  for (int i = 0; i < basis.size(); i++) {
    if (!mask)
      return;
    if (!(mask & (1LL << i)))
      continue;
    if (!basis[i]) {
      basis[i] = mask;
      return;
    }
    mask ^= basis[i];
  }
}

bool exist(vector<int> &basis, int mask) {
  for (int i = 0; i < basis.size(); i++) {
    if (!mask)
      return 1;
    if (!(mask & (1LL << i)))
      continue;
    if (!basis[i])
      return 0;
    mask ^= basis[i];
  }
  return (!mask);
}

bool solve() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  string b;
  cin >> b;
  vector<int> basis(61);
  for (int i = n - 1; i >= 0; i--) {
    if (b[i] == '0') {
      insert(basis, a[i]);
    } else if (!exist(basis, a[i])) {
      return 1;
    }
  }
  return 0;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  // If you hack my code , You are gay;
  int T;
  cin >> T;
  while (T--) {
    cout << solve() << "\\n";
  }
  return 0;
}

Error: 0

Fixed submission:

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

#define ll long long
#define pii pair<int, int>
#define fi first
#define se second
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;

void insert(vector<int> &basis, int mask) {
  for (int i = 0; i < basis.size(); i++) {
    if (!mask)
      return;
    if (!(mask & (1LL << i)))
      continue;
    if (!basis[i]) {
      basis[i] = mask;
      return;
    }
    mask ^= basis[i];
  }
}

bool exist(vector<int> &basis, int mask) {
  for (int i = 0; i < basis.size(); i++) {
    if (!mask)
      return 1;
    if (!(mask & (1LL << i)))
      continue;
    if (!basis[i])
      return 0;
    mask ^= basis[i];
  }
  return (!mask);
}

bool solve() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  string b;
  cin >> b;
  vector<int> basis(61);
  for (int i = n - 1; i >= 0; i--) {
    if (b[i] == '0') {
      insert(basis, a[i]);
    } else if (!exist(basis, a[i])) {
      return 1;
    }
  }
  return 0;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  // If you hack my code , You are gay;
  int T;
  cin >> T;
  while (T--) {
    cout << solve() << "\\n";
  }
  return 0;
}
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

// In the Name of Allah
// Ya Ali

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair

const int maxn = 210;
const int INF = 1e18;

int n, t, a[maxn];
bool use[maxn];
vector<int> vv;
string s;

bool ok(int x) {
  memset(use, false, sizeof use);
  int now = 0;

  vector<int> v1;
  for (auto x : vv)
    v1.pb(x);

  for (int i = 62; i >= 0; i--) {

    int po = -1;
    for (int j = 0; j < v1.size(); j++)
      if ((v1[j] & (1ll << i)) && !use[j])
        po = j;

    bool t1 = (x & (1ll << i)), t2 = (now & (1ll << i));

    if (t1 != t2 && po != -1)
      now ^= v1[po];

    if (po != -1) {
      use[po] = true;
      for (int j = 0; j < v1.size(); j++)
        if (j != po && (v1[j] & (1ll << i)))
          v1[j] ^= v1[po];
    }
  }

  return (now == x);
}

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= n; i++)
      cin >> a[i];
    cin >> s;

    bool ans = 0;
    vv.clear();

    for (int i = n; i >= 1; i--) {
      if (s[i - 1] == '0')
        vv.pb(a[i]);
      else {
        if (!ok(a[i])) {
          ans = 1;
          break;
        }
      }
    }

    cout << ans << "\\n";
  }

  return 0;
}


Error: TLE

Fixed submission:

// In the Name of Allah
// Ya Ali

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair

const int maxn = 210;
const int INF = 1e18;

int n, t, a[maxn];
map<int, bool> mark;
vector<int> dp;
string s;

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= n; i++)
      cin >> a[i];
    cin >> s;

    dp.clear();
    dp.pb(0);
    mark.clear();
    mark[0] = true;

    for (int i = n; i >= 1; i--) {
      vector<int> now;
      if (s[i - 1] == '0') {
        if (mark[a[i]])
          continue;

        for (auto x : dp)
          now.pb(x ^ a[i]);

        for (auto x : now) {
          dp.pb(x);
          mark[x] = true;
        }
      } else {
        if (mark[a[i]])
          continue;
        for (auto x : dp)
          mark[x] = false;
        swap(dp, now);
      }
    }

    cout << 1 - mark[0] << "\\n";
  }

  return 0;
}
Problem p02651 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
#define N 300

const LL k = 60;
LL n, a[N], f[80];
char s[N];

void ins(LL x) {
  for (LL i = k; ~i; --i) {
    if (x >> i & 1) {
      if (!f[i]) {
        f[i] = x;
        return;
      } else
        x ^= f[i];
    }
  }
}

bool pd(LL x) {
  for (LL i = k; ~i; --i) {
    if (x >> i & 1) {
      if (!f[i])
        return 0;
      x ^= f[i];
    }
  }
  return 1;
}

void solve() {
  scanf("%lld", &n);
  for (LL i = 1; i <= n; ++i)
    scanf("%lld", a + i);
  scanf("%s", s + 1);
  memset(f, 0, sizeof f);
  LL flag = 0;
  for (LL i = n; i; --i) {
    if (s[i] == '0')
      ins(a[i]);
    else if (!pd(a[i])) {
      flag = 1;
      break;
    }
  }
  printf("%lld\\n", flag);
}

int main() {
  LL T;
  scanf("%lld", &T);
  while (T--)
    solve();

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
#define N 120

const LL k = 60;
LL n, a[N], f[80];
char s[N];

void ins(LL x) {
  for (LL i = k; ~i; --i) {
    if (x >> i & 1) {
      if (!f[i]) {
        f[i] = x;
        return;
      } else
        x ^= f[i];
    }
  }
}

bool pd(LL x) {
  for (LL i = k; ~i; --i) {
    if (x >> i & 1) {
      if (!f[i])
        return 0;
      x ^= f[i];
    }
  }
  return 1;
}

void solve() {
  scanf("%lld", &n);
  for (LL i = 1; i <= n; ++i)
    scanf("%lld", a + i);
  scanf("%s", s + 1);
  memset(f, 0, sizeof f);
  LL flag = 0;
  for (LL i = n; i; --i) {
    if (s[i] == '0')
      ins(a[i]);
    else if (!pd(a[i])) {
      flag = 1;
      break;
    }
  }
  printf("%lld\\n", flag);
}

int main() {
  LL T;
  scanf("%lld", &T);
  while (T--)
    solve();

  return 0;
}
Problem p02651 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

// #define debug(x) ;
#define debug(x) cerr << #x << " = " << x << "\\n";

ostream &operator<<(ostream &cerr, vector<ll> aux) {
  cerr << "[";
  for (auto e : aux)
    cerr << e << ' ';
  cerr << "]";
  return cerr;
}

const int maxN = 211;
const int maxBit = 60;

int n, t;
ll a[maxN];
char s[maxN];

ll curr[maxBit + 1];
ll reduced;

int reduce(ll val) {
  for (int i = maxBit; i >= 0; i--) {
    if (((val >> i) & 1) == 0)
      continue;
    if (curr[i] == 0) {
      reduced = val;
      return i;
    }
    val ^= curr[i];
  }
  return -1;
}

int solve() {
  memset(curr, 0, sizeof(curr));

  for (int i = n - 1; i >= 0; i--) {
    int lastBit = reduce(a[i]);
    if (lastBit == -1)
      continue;

    if (s[i] == '0') {
      curr[lastBit] = reduced;
    } else {
      return 1;
    }
  }

  return 0;
}

int main() {
  // freopen("test.in", "r", stdin);

  scanf("%d", &t);
  for (int ti = 1; ti <= t; ti++) {
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
      scanf("%lld", &a[i]);
    scanf("\\n%s", s);

    printf("%d\\n", solve());
  }

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

// #define debug(x) ;
#define debug(x) cerr << #x << " = " << x << "\\n";

ostream &operator<<(ostream &cerr, vector<ll> aux) {
  cerr << "[";
  for (auto e : aux)
    cerr << e << ' ';
  cerr << "]";
  return cerr;
}

const int maxN = 111;
const int maxBit = 60;

int n, t;
ll a[maxN];
char s[maxN];

int curr[maxBit + 1];
ll reduced;

int reduce(ll val) {
  for (int i = maxBit; i >= 0; i--) {
    if (((val >> i) & 1) == 0)
      continue;
    if (curr[i] == 0) {
      reduced = val;
      return i;
    }
    val ^= curr[i];
  }
  return -1;
}

int solve() {
  memset(curr, 0, sizeof(curr));

  for (int i = n - 1; i >= 0; i--) {
    int lastBit = reduce(a[i]);
    if (lastBit == -1)
      continue;

    if (s[i] == '0') {
      curr[lastBit] = reduced;
    } else {
      return 1;
    }
  }

  return 0;
}

int main() {
  // freopen("test.in", "r", stdin);

  scanf("%d", &t);
  for (int ti = 1; ti <= t; ti++) {
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
      scanf("%lld", &a[i]);
    scanf("\\n%s", s);

    printf("%d\\n", solve());
  }

  return 0;
}
Problem p02651 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <math.h>
#include <string>

using namespace std;

void reduce(int arr[64][64], int lead[64], int *d) {
  for (int i = 0; i < *d - 1; i++) {
    if (arr[*d - 1][lead[i]] == 1) {
      for (int k = lead[i]; k < 64; k++) {
        arr[*d - 1][k] = arr[*d - 1][k] ^ arr[i][k];
      }
    }
  }
  int t = 0;
  for (int i = 0; i < 64; i++) {
    if (arr[*d - 1][i] != 0) {
      t = 1;
      lead[*d - 1] = i;
      break;
    }
  }
  if (t == 0) {
    *d = *d - 1;
    return;
  }

  for (int i = *d - 2; i >= 0; i--) {
    if (lead[i + 1] < lead[i]) {
      for (int j = 0; j < 64; j++) {
        t = arr[i][j];
        arr[i][j] = arr[i + 1][j];
        arr[i + 1][j] = t;
      }
      t = lead[i];
      lead[i] = lead[i + 1];
      lead[i + 1] = t;
    } else
      return;
  }
  return;
}

int solve() {
  int n;
  cin >> n;
  long *a = new long[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  string s;
  cin >> s;

  int arr[64][64];
  int lead[64];
  int d = 0;
  int t;
  long temp;
  for (int i = s.length() - 1; i >= 0; i--) {
    t = d;
    temp = a[i];
    for (int j = 63; j >= 0; j--) {
      arr[d][j] = temp % 2;
      temp /= 2;
    }
    d++;
    reduce(arr, lead, &d);

    if (s[i] == '1' && t != d)
      return 1;
  }
  return 0;
}

int main(void) {

  long t;
  cin >> t;
  string ans;

  for (int i = 0; i < t; i++) {
    cout << solve() << "\\n";
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#include <math.h>
#include <string>

using namespace std;

void reduce(int arr[64][64], int lead[64], int *d) {
  for (int i = 0; i < *d - 1; i++) {
    if (arr[*d - 1][lead[i]] == 1) {
      for (int k = lead[i]; k < 64; k++) {
        arr[*d - 1][k] = arr[*d - 1][k] ^ arr[i][k];
      }
    }
  }
  int t = 0;
  for (int i = 0; i < 64; i++) {
    if (arr[*d - 1][i] != 0) {
      t = 1;
      lead[*d - 1] = i;
      break;
    }
  }
  if (t == 0) {
    *d = *d - 1;
    return;
  }

  for (int i = *d - 2; i >= 0; i--) {
    if (lead[i + 1] < lead[i]) {
      for (int j = 0; j < 64; j++) {
        t = arr[i][j];
        arr[i][j] = arr[i + 1][j];
        arr[i + 1][j] = t;
      }
      t = lead[i];
      lead[i] = lead[i + 1];
      lead[i + 1] = t;
    } else
      return;
  }
  return;
}

int solve() {
  int n;
  cin >> n;
  long *a = new long[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  string s;
  cin >> s;

  int arr[64][64];
  int lead[64];
  int d = 0;
  int t, temp;
  for (int i = s.length() - 1; i >= 0; i--) {
    t = d;
    temp = a[i];
    for (int j = 63; j >= 0; j--) {
      arr[d][j] = temp % 2;
      temp /= 2;
    }
    d++;
    reduce(arr, lead, &d);

    if (s[i] == '1' && t != d)
      return 1;
  }
  return 0;
}

int main(void) {

  long t;
  cin >> t;
  string ans;

  for (int i = 0; i < t; i++) {
    cout << solve() << "\\n";
  }

  return 0;
}
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807
// (-2^63 <= long < 2^63)

#define INF (1 << 30)
// 1,073,741,824
//= 536,870,912 *2

#define MOD 1000000007

#define Rep0(i, n) for (auto i = 0; i < n; i++)
#define Rep1(i, n) for (auto i = 1; i <= n; i++)
#define Sort(P) sort(P.begin(), P.end())
#define Rev(P) reverse(P.begin(), P.end())

int main() {
  int T;
  cin >> T;
  Rep0(tt, T) {
    int N;
    cin >> N;
    vector<ll> A(N, 0);
    Rep0(i, N) cin >> A.at(i);
    string S;
    cin >> S;
    Rev(A);
    Rev(S);
    if (S.at(0) == '1') {
      cout << 1 << endl;
      continue;
    }
    set<ll> D0;
    bool OK = true;
    D0.insert(0);
    Rep0(i, N) {
      ll AA = A.at(i);
      auto itr = D0.end();
      Rep0(i, D0.size()) {
        itr--;
        AA = min(AA, AA ^ *itr);
      }
      if ('0' == S.at(i)) {
        if (AA != 0)
          D0.insert(AA);
      } else {
        if (AA != 0) {
          OK = false;
          break;
        }
      }
    }
    if (OK)
      cout << 0 << endl;
    else
      cout << 1 << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807
// (-2^63 <= long < 2^63)

#define INF (1 << 30)
// 1,073,741,824
//= 536,870,912 *2

#define MOD 1000000007

#define Rep0(i, n) for (auto i = 0; i < n; i++)
#define Rep1(i, n) for (auto i = 1; i <= n; i++)
#define Sort(P) sort(P.begin(), P.end())
#define Rev(P) reverse(P.begin(), P.end())

int main() {
  int T;
  cin >> T;
  Rep0(tt, T) {
    int N;
    cin >> N;
    vector<ll> A(N, 0);
    Rep0(i, N) cin >> A.at(i);
    string S;
    cin >> S;
    Rev(A);
    Rev(S);
    if (S.at(0) == '1') {
      cout << 1 << endl;
      continue;
    }
    set<ll> D0;
    set<ll> D1;
    D0.insert(0);
    Rep0(i, N) {
      D1.clear();
      if ('0' == S.at(i)) {
        for (auto DD : D0) {
          D1.insert(DD);
          D1.insert(DD ^ A.at(i));
        }
      } else {
        for (auto DD : D0) {
          if (D0.count(DD ^ A.at(i)))
            D1.insert(DD);
        }
      }
      swap(D0, D1);
    }
    cout << 1 - D0.count(0) << endl;
  }
  return 0;
}
Problem p02651 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int main() {
  lint T;
  cin >> T;

  while (T--) {
    int N;
    cin >> N;

    vector<lint> A(N);
    for (auto &elem : A)
      cin >> elem;

    string S;
    cin >> S;
    if (S[N - 1] == '1') {
      cout << 1 << endl;
      continue;
    }

    reverse(A.begin(), A.end());
    reverse(S.begin(), S.end());

    multiset<lint> st;
    bool zero = true;
    for (lint i = 0; i < N; i++) {
      if (S[i] == '0') {
        st.insert(A[i]);
      } else {
        vector<lint> a(st.begin(), st.end());
        lint K = A[i];
        // 移植：https://atcoder.jp/contests/code-thanks-festival-2017-open/submissions/1834702

        lint kakutei = 0;
        for (lint k = 60; k >= 0; k--) {
          lint po = 0;
          for (lint j = a.size() - 1; j >= 0; j--) {
            if (po == 0 && a[j] >> (k + 1) == 0 && a[j] >> k == 1 &&
                (a[j] ^ kakutei) >> k == K >> k) {
              po = a[j];
              kakutei ^= po;
            } else if (po == 0 && a[j] >> (k + 1) == 0 && a[j] >> k == 1)
              po = a[j];
            else if (po != 0 && a[j] > (po ^ a[j]))
              a[j] = po ^ a[j];
          }
        }
        zero &= (kakutei == K);
      }
    }

    cout << 1 - zero << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int main() {
  lint T;
  cin >> T;

  while (T--) {
    int N;
    cin >> N;

    vector<lint> A(N);
    for (auto &elem : A)
      cin >> elem;

    string S;
    cin >> S;

    reverse(A.begin(), A.end());
    reverse(S.begin(), S.end());

    set<int> st;
    bool zero = true;
    for (lint i = 0; i < N; i++) {
      if (S[i] == '0') {
        st.insert(A[i]);
      } else {
        vector<lint> a(st.begin(), st.end());
        lint K = A[i];
        // 移植：https://atcoder.jp/contests/code-thanks-festival-2017-open/submissions/1834702

        lint kakutei = 0;
        for (lint k = 60; k >= 0; k--) {
          lint po = 0;
          for (lint j = N - 1; j >= 0; j--) {
            if (po == 0 && a[j] >> (k + 1) == 0 && a[j] >> k == 1 &&
                (a[j] ^ kakutei) >> k == K >> k) {
              po = a[j];
              kakutei ^= po;
            } else if (po == 0 && a[j] >> (k + 1) == 0 && a[j] >> k == 1)
              po = a[j];
            else if (po != 0 && a[j] > (po ^ a[j]))
              a[j] = po ^ a[j];
          }
        }
        zero &= (kakutei == K);
      }
    }

    cout << 1 - zero << endl;
  }
}