alexjercan/bugnet huggingface dataset:
Problem p00295 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
char box[30];
void input();
bool check();
bool check2(int[2]);
int solve(int);
void turn(int);
int ft[6][2] = {{0, 9}, {9, 12}, {12, 15}, {15, 18}, {18, 21}, {21, 30}};
int main() {
  int time;
  cin >> time;
  for (int i = 0; i < time; ++i) {
    input();
    cout << solve(0) << endl;
  }
  return 0;
}

int solve(int num) {
  if (num == 8 || check()) {
    return num;
  }
  int res = 8;
  for (int i = 0; i < 4; ++i) {
    turn(i);
    res = min(res, solve(num + 1));
    turn(i);
  }
  return res;
}
void turn(int num) {
  switch (num) {
  case 0:
    swap(box[6], box[21]);
    swap(box[7], box[22]);
    swap(box[8], box[23]);
    swap(box[9], box[11]);
    swap(box[17], box[12]);
    break;
  case 1:
    swap(box[8], box[27]);
    swap(box[5], box[24]);
    swap(box[2], box[21]);
    swap(box[12], box[14]);
    swap(box[11], box[18]);
    break;
  case 2:
    swap(box[0], box[27]);
    swap(box[1], box[28]);
    swap(box[2], box[29]);
    swap(box[18], box[20]);
    swap(box[14], box[15]);
    break;
  case 3:
    swap(box[0], box[23]);
    swap(box[3], box[26]);
    swap(box[6], box[29]);
    swap(box[15], box[17]);
    swap(box[9], box[20]);
    break;
  }
}
void input() {
  for (int i = 0; i < 30; ++i) {
    cin >> box[i];
  }
}

bool check() {
  for (int i = 0; i < 6; ++i) {
    if (check2(ft[i]))
      return false;
  }
  return true;
}

bool check2(int j[2]) {
  for (int i = j[0] + 1; i < j[1]; ++i) {
    if (box[j[0]] != box[i])
      return true;
  }
  return false;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
char box[30];
void input();
bool check();
bool check2(int[2]);
int solve(int);
void turn(int);
int ft[6][2] = {{0, 9}, {9, 12}, {12, 15}, {15, 18}, {18, 21}, {21, 30}};

int main() {
  int time;
  cin >> time;
  for (int i = 0; i < time; ++i) {
    input();
    cout << solve(0) << endl;
  }
  return 0;
}

int solve(int num) {
  if (check())
    return num;
  int res = 10;
  for (int i = 0; i < 4; ++i) {
    turn(i);
    res = min(res, solve(num + 1));
    turn(i);
  }
  return res;
}
void turn(int num) {
  switch (num) {
  case 0:
    swap(box[6], box[21]);
    swap(box[7], box[22]);
    swap(box[8], box[23]);
    swap(box[9], box[11]);
    break;
  case 1:
    swap(box[8], box[27]);
    swap(box[5], box[24]);
    swap(box[2], box[21]);
    swap(box[12], box[14]);
    break;
  case 2:
    swap(box[0], box[27]);
    swap(box[1], box[28]);
    swap(box[2], box[29]);
    swap(box[18], box[20]);
    break;
  case 3:
    swap(box[0], box[23]);
    swap(box[3], box[26]);
    swap(box[6], box[29]);
    swap(box[15], box[17]);
    break;
  }
}
void input() {
  for (int i = 0; i < 30; ++i) {
    cin >> box[i];
  }
}

bool check() {
  for (int i = 0; i < 6; ++i) {
    if (check2(ft[i]))
      return false;
  }
  return true;
}

bool check2(int j[2]) {
  for (int i = j[0] + 1; i < j[1]; ++i) {
    if (box[j[0]] != box[i])
      return true;
  }
  return false;
}
Problem p00296 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

int a[200000];
int q[1000];
int f[200000];
int main() {
  int n, m, Q;
  scanf("%d%d%d", &n, &m, &Q);
  memset(f, 0, sizeof(f));
  REP(i, m) scanf("%d", a + i);
  REP(i, Q) scanf("%d", q + i);
  list<int> ls;
  REP(i, n) ls.push_back(i);
  auto it = ls.begin();
  REP(i, m) {
    int x = a[i];
    if (a[i] & 1) {
      REP(_, x) {
        if (it == ls.begin()) {
          it = prev(ls.end());
        } else {
          it--;
        }
      }
    } else {
      REP(_, x) {
        it++;
        if (it == ls.end())
          it = ls.begin();
      }
    }
    f[*it] = 1;
    it = ls.erase(it);
    if (it == ls.end())
      it = ls.begin();
  }
  REP(i, Q) printf("%d\\n", !f[q[i]]);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

int a[200000];
int q[1000];
int f[200000];
int main() {
  int n, m, Q;
  scanf("%d%d%d", &n, &m, &Q);
  memset(f, 0, sizeof(f));
  REP(i, m) scanf("%d", a + i);
  REP(i, Q) scanf("%d", q + i);
  list<int> ls;
  REP(i, n) ls.push_back(i);
  auto it = ls.begin();
  REP(i, m) {
    int x = a[i] % ls.size();
    if (a[i] & 1) {
      REP(_, x) {
        if (it == ls.begin()) {
          it = prev(ls.end());
        } else {
          it--;
        }
      }
    } else {
      REP(_, x) {
        it++;
        if (it == ls.end())
          it = ls.begin();
      }
    }
    f[*it] = 1;
    it = ls.erase(it);
    if (it == ls.end())
      it = ls.begin();
  }
  REP(i, Q) printf("%d\\n", !f[q[i]]);
}
Problem p00296 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <vector>
using namespace std;
bool r[200000];
int main() {
  int n, m, q;
  cin >> n >> m >> q;
  list<int> a;
  fill(r, r + n, true);
  a.push_back(-1);
  for (int i = 0; i < n; i++)
    a.push_back(i);
  list<int>::iterator it = a.begin(), it2;
  it++;
  for (int z = 0; z < m; z++) {
    int s;
    cin >> s;
    if (s % 2 == 0) {
      for (int i = 0; i < s; i++) {
        it++;
        if (it == a.end()) {
          it = a.begin();
          it++;
        }
      }
    } else {
      for (int i = 0; i < s; i++) {
        it--;
        if (it == a.begin()) {
          it = a.end();
          it--;
        }
      }
    }
    it2 = it;
    r[(*it)] = false;
    it2++;
    a.erase(it);
    it = it2;
    if (it == a.end()) {
      it = a.begin();
      it++;
    }
  }
  for (int z = 0; z < q; z++) {
    int q;
    cin >> q;
    if (r[q])
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
bool a[200000];
int main() {
  int n, m, q;
  cin >> n >> m >> q;
  fill(a, a + n, true);
  int p = 0;
  int m2 = m;
  for (int i = 0; i < m; i++) {
    int b;
    cin >> b;
    if (m2 != 0) {
      if (b % 2 == 0) {
        for (int j = 0; j < b; j++) {
          p++;
          if (p >= n)
            p = 0;
          while (!a[p] && m2 != 0) {
            p++;
            if (p >= n)
              p = 0;
          }
        }
        a[p] = false;
        m2--;
        p++;
        if (p >= n)
          p = 0;
        while (!a[p] && m2 != 0) {
          p++;
          if (p >= n)
            p = 0;
        }
      } else {
        for (int i = 0; i < b; i++) {
          p--;
          if (p < 0)
            p = n - 1;
          while (!a[p] && m2 != 0) {
            p--;
            if (p < 0)
              p = n - 1;
          }
        }
        a[p] = false;
        p++;
        m2--;
        if (p >= n)
          p = 0;
        while (!a[p] && m2 != 0) {
          p++;
          if (p >= n)
            p = 0;
        }
      }
    }
  }
  for (int i = 0; i < q; i++) {
    int c;
    cin >> c;
    if (a[c])
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
}
Problem p00296 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int prev[200007] = {}, next[200007] = {};
int main() {
  int N, M, Q, i, a, r, p = 0, j;
  scanf("%d %d %d", &N, &M, &Q);
  for (i = 0; i < N; i++) {
    prev[i] = (i + N - 1) % N;
    next[i] = (i + 1) % N;
  }
  for (i = 0; i < M; i++) {
    scanf("%d", &a);

    for (j = 0; j < a; j++)
      p = a % 2 ? prev[p] : next[p];
    next[prev[p]] = next[p], prev[next[p]] = prev[p];

    r = next[p];
    next[p] = -1;
    prev[p] = -1;
    p = r;
  }
  for (i = 0; i < Q; i++) {
    scanf("%d", &a);
    puts(prev[a] != -1 ? "1" : "0");
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>
#define MAXN 200000
#define MAXQ 1000
int p[MAXN], a[MAXN];
int main() {
  int N, M, Q, q[MAXQ], i, ps = 0, c1, c2, c3;
  scanf("%d %d %d", &N, &M, &Q);
  for (i = 0; i < M; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 0; i < Q; i++) {
    scanf("%d", &q[i]);
  }
  memset(p, 0, N);
  for (i = 0; i < M; i++) {
    c1 = 0;
    c2 = 0;
    c3 = 1;
    if (a[i] % 2 == 0) {
      while (1) {
        c1++;
        c2++;
        if (p[(ps + c1) % N] == 1) {
          c2--;
          continue;
        }
        if (c2 == a[i]) {
          p[(ps + c1) % N] = 1;
          while (1) {
            if (p[(ps + c1 + c3) % N] == 0) {
              ps = (ps + c1 + c3) % N;
              break;
            }
            c3++;
          }
          break;
        }
      }
    } else {
      while (1) {
        c1++;
        c2++;
        if (p[(ps - c1 + N) % N] == 1) {
          c2--;
          continue;
        }
        if (c2 == a[i]) {
          p[(ps - c1 + N) % N] = 1;
          while (1) {
            if (p[(ps - c1 + N + 1) % N] == 0) {
              ps = (ps - c1 + N + c3) % N;
              break;
            }
            c3++;
          }
          break;
        }
      }
    }
  }
  for (i = 0; i < Q; i++) {
    printf("%d\\n", (p[q[i]] + 1) % 2);
  }
  return 0;
}
Problem p00296 (C++) — buggy submission, verdict: Runtime Error

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

list<int> L;
signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  for (int d = 0; d < a; d++) {
    L.push_back(d);
  }
  auto f = L.begin();
  for (int d = 0; d < b; d++) {
    int e;
    scanf("%d", &e);
    for (int g = 0; g < e; g++) {
      if (e & 1) {
        if (f == L.begin())
          f = --L.end();
        else
          f--;
      } else {
        f++;
        if (f == L.end())
          f = L.begin();
      }
    }
    L.erase(f);
    f--;
    f++;
    if (f == L.end())
      f = L.begin();
  }
  for (int s = 0; s < c; s++) {
    int k;
    scanf("%d", &k);
    cout << binary_search(L.begin(), L.end(), k) << endl;
  }
}

Error: -11

Fixed submission:

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

list<int> L;
signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  for (int d = 0; d < a; d++) {
    L.push_back(d);
  }
  auto f = L.begin();
  for (int d = 0; d < b; d++) {
    int e;
    scanf("%d", &e);
    for (int g = 0; g < e; g++) {
      if (e & 1) {
        if (f == L.begin())
          f = --L.end();
        else
          f--;
      } else {
        f++;
        if (f == L.end())
          f = L.begin();
      }
    }
    L.erase(f);
    if (f == L.end())
      f = L.begin();
  }
  for (int s = 0; s < c; s++) {
    int k;
    scanf("%d", &k);
    cout << binary_search(L.begin(), L.end(), k) << endl;
  }
}
Problem p00296 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

const int max_n = 200000;

int n, m, q;
int bit[max_n * 2 + 1];

void add(int i, int x) {
  while (i <= n * 2) {
    bit[i] += x;
    i += i & -i;
  }
}

int sum(int i) {
  int s = 0;
  while (i > 0) {
    s += bit[i];
    i -= i & -i;
  }
  return s;
}

int main() {
  scanf("%d%d%d", &n, &m, &q);
  int p = 0;
  rep(i, m) {
    int a;
    scanf("%d", &a);
    int len = n - i;
    if (a % 2 == 0) {
      a = a % len;
    } else {
      a = a % len;
      a = (len - a) % len;
    }
    int lb = -1, ub = n * 2 - 1;
    while (ub - lb > 1) {
      int mid = (lb + ub) / 2;
      int del = sum(mid + 1) - sum(p + 1);
      if (mid - p - del >= a) {
        ub = mid;
      } else {
        lb = mid;
      }
    }
    p = ub % n;
    // printf("first: %d\\n", p);
    add(p + 1, 1);
    add(p + n + 1, 1);
    lb = -1, ub = n * 2 - 1;
    while (ub - lb > 1) {
      int mid = (lb + ub) / 2;
      int del = sum(mid + 1) - sum(p + 1);
      if (mid - p - del >= 1) {
        ub = mid;
      } else {
        lb = mid;
      }
    }
    p = ub % n;
    // printf("second: %d\\n", p);
  }
  rep(i, q) {
    int t = 0;
    scanf("%d", &t);
    int v = sum(t + 1) - sum(t);
    printf("%d\\n", 1 - v);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

int n, m, q;
bool x[200000];

int main() {
  scanf("%d%d%d", &n, &m, &q);
  int p = 0;
  rep(i, m) {
    int a;
    scanf("%d", &a);
    bool r = a % 2 == 1;
    while (a > 0) {
      if (r) {
        p = (p + n - 1) % n;
      } else {
        p = (p + 1) % n;
      }
      if (!x[p]) {
        --a;
      }
    }
    x[p] = true;
    while (x[p]) {
      p = (p + 1) % n;
    }
  }
  rep(i, q) {
    int t;
    scanf("%d", &t);
    printf("%d\\n", (int)!x[t]);
  }
  return 0;
}
Problem p00296 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <stdio.h>
using namespace std;
int v[210000];
int L[210000];
int R[210000];
int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  for (int i = 0; i < a; i++) {
    v[i] = 1;
    L[i] = (i + a - 1) % a;
    R[i] = (i + 1) % a;
  }
  int now = 0;
  for (int i = 0; i < b; i++) {
    int d;
    scanf("%d", &d);
    if (d % 2) {
      for (int j = 0; j < d; j++)
        now = L[now];
      v[now] = 0;
      int l = L[now];
      int r = R[now];
      R[l] = r;
      L[r] = l;
      now = r;
    } else {
      for (int j = 0; j < d; j++)
        now = R[now];
      v[now] = 0;
      int l = L[now];
      int r = R[now];
      R[l] = r;
      L[r] = l;
      now = r;
    }
  }
  for (int i = 0; i < c; i++) {
    int d;
    scanf("%d", &d);
    printf("%d\\n", v[d]);
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <stdio.h>
using namespace std;
int v[110000];
int L[110000];
int R[110000];
int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  for (int i = 0; i < a; i++) {
    v[i] = 1;
    L[i] = (i + a - 1) % a;
    R[i] = (i + 1) % a;
  }
  int now = 0;
  for (int i = 0; i < b; i++) {
    int d;
    scanf("%d", &d);
    if (d % 2) {
      for (int j = 0; j < d; j++)
        now = L[now];
      v[now] = 0;
      int l = L[now];
      int r = R[now];
      R[l] = r;
      L[r] = l;
      now = r;
    } else {
      for (int j = 0; j < d; j++)
        now = R[now];
      v[now] = 0;
      int l = L[now];
      int r = R[now];
      R[l] = r;
      L[r] = l;
      now = r;
    }
  }
  for (int i = 0; i < c; i++) {
    int d;
    scanf("%d", &d);
    printf("%d\\n", v[d]);
  }
}
Problem p00296 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int prev[200000], next[200000];
bool ok[200000];
int N, M, Q;

int main() {
  cin >> N >> M >> Q;

  for (int i = 0; i < N; i++) {
    prev[i] = (i - 1 + N) % N;
    next[i] = (i + 1) % N;
  }

  int cur = 0;
  while (M--) {
    int a;
    cin >> a;

    if (a & 1)
      while (a--)
        cur = prev[cur];

    else
      while (a--)
        cur = next[cur];

    ok[cur] = true;
    next[prev[cur]] = next[cur];
    prev[next[cur]] = prev[cur];

    cur = next[cur];
  }

  while (Q--) {
    int q;
    cin >> q;
    cout << 1 - ok[q] << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define INT(name)                                                              \\
  int name;                                                                    \\
  scanf("%d", &name);
#define VINT(name, n)                                                          \\
  vector<int> name(n);                                                         \\
  for (int i = 0; i < n; i++)                                                  \\
    scanf("%d", &name[i]);
#define ll long long
#define ull unsigned long long

using namespace std;

int main(int argc, char const *argv[]) {
  INT(N)

  INT(M)

  INT(Q)

  vector<bool> people(N);
  for (int i = 0; i < N; i++)
    people[i] = true;

  VINT(number, M)

  int i = 0;
  for (int j = 0; j < M; j++) {
    bool plus = (number[j] + 1) % 2;
    while (number[j]) {
      i += plus ? 1 : -1;
      i = (i == N) ? 0 : (i == -1 ? N - 1 : i);
      if (people[i] == true)
        number[j]--;
    }
    people[i] = false;
    while (!people[i]) {
      i++;
      i = (i == N) ? 0 : i;
    }
  }

  for (int i = 0; i < Q; i++) {
    int temp;
    scanf("%d", &temp);
    printf("%d\\n", (int)people[temp]);
  }

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

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

typedef long long ll;
typedef pair<int, int> P;

#define pb push_back
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define dep(i, a, n) for (int i = (a); i >= (n); i--)
#define mod 1e9 + 7

__attribute__((constructor)) void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

struct L {
  int back, front;
  bool f;
};
int n, m, q;
vector<L> a(200001);

int main() {
  cin >> n >> m >> q;

  rep(i, 0, n) {
    a[i].front = i + 1;
    a[i].back = i - 1;
    a[i].f = true;
    if (i == 0)
      a[i].back = n - 1;
    if (i == n - 1)
      a[i].front = 0;
  }

  int p = 0;
  rep(i, 0, m) {
    int b;
    cin >> b;
    rep(j, 0, b) {
      if (b % 2)
        p = a[p].back;
      else
        p = a[p].front;
    }

    a[p].f = false;
    a[a[p].back].front = a[p].front;
    a[a[p].front].back = a[p].back;
    p = a[p].front;
  }

  rep(i, 0, q) {
    int b;
    cin >> b;
    cout << (a[b].f ? 1 : 0) << endl;
  }
}

Error: TLE

Fixed submission:

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

typedef long long ll;
typedef pair<int, int> P;

#define pb push_back
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define dep(i, a, n) for (int i = (a); i >= (n); i--)
#define mod 1e9 + 7

__attribute__((constructor)) void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int n, m, q;
  cin >> n >> m >> q;
  vector<int> a(n);
  map<int, bool> ma;
  rep(i, 0, n) a[i] = i;

  int p = 0;
  rep(i, 0, m) {
    int b;
    cin >> b;
    if (b % 2 == 1)
      p -= b;
    else
      p += b;

    if (p < 0)
      p = a.size() - (-p % a.size());
    if (p > a.size() - 1)
      p = p % a.size();

    a.erase(a.begin() + p);
    if (p > a.size() - 1)
      p = 0;
  }

  rep(i, 0, a.size()) ma[a[i]] = true;

  rep(i, 0, q) {
    int b;
    cin >> b;
    cout << (ma[b] ? 1 : 0) << endl;
  }
}
Problem p00296 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, M, Q;
  cin >> N >> M >> Q;

  vector<int> f(N), b(N);
  vector<bool> exist(N);
  for (int i = 0; i < N; ++i) {
    f[i] = (i + 1) % N;
    b[i] = (i - 1 + N) % N;
    exist[i] = 1;
  }

  int baton = 0;
  for (int i = 0; i < M; ++i) {
    int a;
    cin >> a;
    for (int j = 0; j < a; ++j) {
      baton = (a & 1 ? b[baton] : f[baton]);
    }
    exist[baton] = 0;
    b[f[baton]] = b[baton];
    f[b[baton]] = f[baton];
    baton = f[baton];
  }
  for (int i = 0; i < Q; ++i) {
    int q;
    cin >> q;
    cout << exist[q] << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <list>
#include <vector>

using namespace std;

int main() {
  int N, M, Q;
  list<int> per;

  cin >> N >> M >> Q;

  for (int i = 0; i < N; ++i) {
    per.push_back(i);
  }
  auto baton = per.begin();
  for (int i = 0; i < M; ++i) {
    int a;
    cin >> a;
    for (int j = 0; j < a; ++j) {
      if (a % 2 == 0) {
        if (++baton == per.end()) {
          baton = per.begin();
        }
      } else {
        if (baton == per.begin()) {
          baton = per.end();
        }
        --baton;
      }
    }
    per.erase(baton);
    if (++baton == per.end()) {
      baton = per.begin();
    }
  }

  vector<bool> exist(N);
  for (const auto &p : per) {
    exist[p] = 1;
  }

  for (int i = 0; i < Q; ++i) {
    int q;
    cin >> q;
    cout << exist[q] << endl;
  }
  return 0;
}
Problem p00296 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;
int n, m, q, h, x[200003], f[200003], g[200003];
int main() {
  cin >> n >> m >> q;
  int D = 0;
  for (int i = 0; i < n; i++) {
    x[i] = 0;
    f[i] = (i + 1) % n;
    g[i] = (i + n - 1) % n;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &h);
    if (h % 2 == 0) {
      for (int j = 0; j < h; j++)
        D = f[D];
    }
    if (h % 2 == 1) {
      for (int j = 0; j < h; j++)
        D = g[D];
    }
    f[g[D]] = f[D];
    g[f[D]] = g[D];
    x[D] = 1;
    D = f[D];
  }
  for (int i = 0; i < q; i++) {
    scanf("%d", &h);
    cout << 1 - x[h] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
bool x[200000];
int n, m, q, a, turn, cnt;
int main() {
  cin >> n >> m >> q;
  turn = 0;
  for (int i = 0; i < m; i++) {
    cin >> a;
    if (a % 2 == 0) {
      a %= (n - i);
      cnt = 0;
      while (true) {
        if (cnt >= a && x[turn] == 0) {
          x[turn] = 1;
          break;
        }
        if (x[turn] == 0) {
          cnt++;
        }
        turn++;
        if (turn >= n) {
          turn = 0;
        }
      }
    } else {
      a %= (n - i);
      cnt = 0;
      while (true) {
        if (cnt >= a && x[turn] == 0) {
          x[turn] = 1;
          break;
        }
        if (x[turn] == 0) {
          cnt++;
        }
        turn--;
        if (turn < 0) {
          turn = n - 1;
        }
      }
    }
    turn++;
    if (turn >= n) {
      turn = 0;
    }
    while (x[turn] == 1) {
      turn++;
      if (turn >= n) {
        turn = 0;
      }
    }
  }
  for (int i = 0; i < q; i++) {
    cin >> a;
    if (x[a] == 1) {
      cout << '0' << endl;
    } else {
      cout << '1' << endl;
    }
  }
}
Problem p00296 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M, Q;
  cin >> N >> M >> Q;
  bool e[N];
  list<pair<bool, int>> ex;

  for (int i = 0; i < N; i++) {
    ex.push_back(make_pair(true, i));
    e[i] = true;
  }
  list<pair<bool, int>>::iterator it = ex.begin();
  for (int i = 0; i < M; i++) {
    int a;
    cin >> a;
    if (a % 2 == 0) {
      // c = (c + a) % N;
      for (int i = 0; i < a; i++) {
        it++;
        if (it == ex.end())
          it = ex.begin();
      }
    } else {
      // c = ((c + N) - a) % N;
      for (int i = 0; i < a; i++) {
        if (it == ex.begin())
          it = ex.end();
        it--;
      }
    }
    e[(*it).second] = false;
    /*
    cout << '(';
    cout << it->second << ", ";
    */
    it = ex.erase(it);
    if (it == ex.end())
      it = ex.begin();
    // cout << it->second << ")" << endl;
  }
  // cout << "--" << endl;
  // for(it = ex.begin(); it != ex.end(); it++) cout << it->second << endl;
  for (int i = 0; i < Q; i++) {
    int q;
    cin >> q;
    cout << e[q] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M, Q;
  cin >> N >> M >> Q;
  bool ex[N];

  for (int i = 0; i < N; i++) {
    ex[i] = true;
  }
  int c = 0;
  for (int i = 0; i < M; i++) {
    int a;
    cin >> a;
    if (a % 2 == 0) {
      // c = (c + a) % N;
      for (int i = 0; i < a; i++) {
        c = (c + 1) % N;
        if (ex[c] == false)
          i--;
      }
    } else {
      // c = ((c + N) - a) % N;
      for (int i = 0; i < a; i++) {
        c = (c + N - 1) % N;
        if (ex[c] == false)
          i--;
      }
    }
    ex[c] = false;
    // c = (c + 1) % N;
    while (ex[c] == false) {
      c = (c + 1) % N;
    }
  }
  for (int i = 0; i < Q; i++) {
    int q;
    cin >> q;
    cout << ex[q] << endl;
  }
  return 0;
}