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

#include <cstdio>
#include <iostream>
#include <list>
#include <set>

using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)

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

  list<int> lis;
  REP(i, N) lis.push_back(i);

  list<int>::iterator itr = lis.begin();

  REP(i, M) {
    int a;
    scanf("%d", &a);

    bool d = a & 1;
    REP(j, a) {
      if (d) {
        if (itr == lis.begin())
          itr = lis.end();
        itr--;
      } else {
        itr++;
        if (itr == lis.end())
          itr = lis.begin();
      }
    }

    itr = lis.erase(itr);
    if (itr == lis.end())
      itr = lis.begin();
  }

  set<int> s;
  for (itr = lis.begin(); itr != lis.end(); itr++) {
    s.insert(*itr);
  }

  REP(i, Q) {
    int q;
    scanf("%d", &q);
    if (s.find(q) != s.end())
      puts("1");
    else
      puts("0");
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#include <list>
#include <set>

using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)

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

  list<int> lis;
  REP(i, N) lis.push_back(i);

  list<int>::iterator itr = lis.begin();

  REP(i, M) {
    int a;
    scanf("%d", &a);

    a %= N - i;

    bool d = a & 1;
    REP(j, a) {
      if (d)
        itr--;
      else
        itr++;

      if (itr == lis.end() || itr == lis.begin()) {
        if (d)
          itr--;
        else
          itr++;
      };
    }

    itr = lis.erase(itr);
    if (itr == lis.end())
      itr = lis.begin();
  }

  set<int> s;
  for (itr = lis.begin(); itr != lis.end(); itr++)
    s.insert(*itr);

  REP(i, Q) {
    int q;
    cin >> q;
    if (s.find(q) != s.end())
      puts("1");
    else
      puts("0");
  }
  return 0;
}
Problem p00296 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

const int max_n = 200000;

struct student {
  bool win;
  int id;
  int next;
  int prev;
};

int main() {
  int n, m, q;
  int a[max_n];
  int query[1000];

  cin >> n >> m >> q;
  for (int i = 0; i < m; i++)
    scanf("%d", &a[i]); // cin >> a[i];
  for (int i = 0; i < q; i++)
    scanf("%d", &query[i]); // cin >> query[i];

  student students[max_n];

  for (int i = 0; i < n; i++) {
    students[i].win = true;
    students[i].id = i;
    students[i].next = (i + 1) % n;
    students[i].prev = (i - 1 + n) % n;
  }

  int baton = 0;
  for (int i = 0; i < m; i++) {
    if (a[i] % 2)
      for (int k = 0; k < a[i]; k++)
        baton = students[baton].prev;
    else
      for (int k = 0; k < a[i]; k++)
        baton = students[baton].next;

    int pre = students[baton].prev;
    int nxt = students[baton].next;
    students[baton].win = false;
    students[pre].next = nxt;
    students[nxt].prev = pre;
    baton = nxt;
  }

  for (int i = 0; i < q; i++) {
    if (students[query[i]].win)
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

const int max_n = 200000;

struct students {
  int id;
  students *next;
};

int main() {
  int n, m, q;
  int a[max_n];
  int query[1000];

  cin >> n >> m >> q;
  for (int i = 0; i < m; i++)
    scanf("%d", &a[i]); // cin >> a[i];
  for (int i = 0; i < q; i++)
    scanf("%d", &query[i]); // cin >> query[i];

  for (int i = 0; i < q; i++) {
    int r = n; // ??????????????°
    int baton = 0;
    int target = query[i];
    bool found = false;

    for (int j = 0; j < m; j++) {
      if (a[j] % 2)
        baton = (baton - a[j] + 100 * r) % r;
      else
        baton = (baton + a[j]) % r;
      // cout << baton << ' ';
      if (target == baton) {
        cout << 0 << endl;
        found = true;
        break;
      }
      r--;
      if (target > baton)
        target--;
      baton = baton % r;
      // cout << baton << endl;
    }
    if (!found)
      cout << 1 << endl;
  }
  return 0;
}
Problem p00296 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <vector>

using namespace std;
typedef long long ll;

#define mod 1000000007
#define INF 1000000000
#define SIZE 100000

bool ans[200000];

int main() {
  int n, m, q;
  int a, b;
  list<int> stu;

  scanf("%d%d%d", &n, &m, &q);

  for (int i = 0; i < n; i++) {
    stu.push_back(i);
  }

  list<int>::iterator it = stu.begin(), it2;

  for (int i = 0; i < m; i++) {
    scanf("%d", &a);

    for (int j = 0; j < a; j++) {
      if (a % 2 == 0) {
        it++;
        if (stu.end() == it)
          it = stu.begin();
      } else {
        if (it == stu.begin())
          it = stu.end();
        it--;
      }
    }

    it2 = it;
    it2++;
    stu.erase(it);
    it = it2;
    if (it == stu.end())
      it = stu.begin();
  }

  for (it2 = stu.begin(); it2 != stu.end(); it2++) {
    ans[*it2] = true;
  }

  for (int i = 0; i < q; i++) {
    scanf("%d", &b);
    puts(ans[b] ? "1" : "0");
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <vector>

using namespace std;
typedef long long ll;

#define mod 1000000007
#define INF 1000000000
#define SIZE 100000

int main() {
  int n, m, q;
  int a, b;
  bool ans[200000] = {0};
  list<int> stu;

  scanf("%d%d%d", &n, &m, &q);

  for (int i = 0; i < n; i++) {
    stu.push_back(i);
  }

  list<int>::iterator it = stu.begin(), it2;

  for (int i = 0; i < m; i++) {
    scanf("%d", &a);

    for (int j = 0; j < a; j++) {
      if (a % 2 == 0) {
        it++;
        if (stu.end() == it)
          it = stu.begin();
      } else {
        if (it == stu.begin())
          it = stu.end();
        else
          it--;
      }
    }
    it = stu.erase(it);
  }

  for (it2 = stu.begin(); it2 != stu.end(); it2++) {
    ans[*it2] = true;
  }

  for (int i = 0; i < q; i++) {
    scanf("%d", &b);
    puts(ans[b] ? "1" : "0");
  }

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

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

struct Student {
  int prev, next;
};

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

  vector<bool> alive(N, true);
  vector<Student> student(N);
  for (int i = 0; i < N; ++i) {
    student[i].prev = (i - 1 + N) % N;
    student[i].next = (i + 1) % N;
  }

  int button = 0;
  for (int i = 0; i < M; ++i) {
    int a;
    cin >> a;
    bool odd = a & 1;
    while (a-- > 0) {
      button = odd ? student[button].prev : student[button].next;
    }
    alive[button] = false;
    student[student[button].prev].next = student[button].next;
    student[student[button].next].prev = student[button].prev;
    button = student[button].next;
  }

  for (int i = 0; i < Q; ++i) {
    int q;
    cin >> q;
    cout << (alive[q] ? 1 : 0) << endl;
  }
}

Error: TLE

Fixed submission:

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

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

  vector<bool> alive(N, true);

  int button = 0;
  for (int i = 0; i < M; ++i) {
    int a;
    cin >> a;
    int d = (a & 1) ? -1 : +1;
    while (a-- > 0) {
      do {
        button = (button + d + N) % N;
      } while (!alive[button]);
    }
    alive[button] = false;
    do {
      button = (button + 1) % N;
    } while (!alive[button]);
  }

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

#include <stdio.h>
int next[200001];
int prev[200001];
int main() {
  int N, M, Q;
  int a, q;
  int i, j, p = 0, r = 0;
  scanf("%d %d %d", &N, &M, &Q);
  for (i = 0; i < N; i++) {
    next[i] = (i + 1) % N;
    prev[i] = (i + N - 1) % N;
  }
  for (i = 0; i < M; i++) {
    scanf("%d", &a);
    for (j = 0; j < a; j++)
      p = a % 2 == 1 ? 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", &q);
    if (next[q] != -1)
      printf("1\\n");
    else
      printf("0\\n");
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
int student[2000004];
int main() {
  int N, M, Q;
  int a, q, have = 0;
  memset(student, 0, sizeof(student));
  cin >> N >> M >> Q;
  for (int i = 0; i < M; i++) {
    cin >> a;
    if (a % 2 == 0) {
      while (a != 0) {
        have++;
        if (have == N)
          have = 0;
        if (student[have] == 0) {
          a--;
        }
      }
    } else {
      while (a != 0) {
        have--;
        if (have == -1)
          have = N - 1;
        if (student[have] == 0) {
          a--;
        }
      }
    }
    student[have] = 1;
    while (true) {
      have++;
      if (have == N)
        have = 0;
      if (student[have] == 0)
        break;
    }
  }
  for (int i = 0; i < Q; i++) {
    cin >> q;
    if (student[q] == 1)
      cout << "0";
    else
      cout << "1";
    cout << endl;
  }
  return 0;
}
Problem p00296 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
int main() {
  int n, m, k;
  bool ans[200000];
  int a[200000];
  int q[1000];
  int bfr[200000];
  int nxt[200000];
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < m; i++)
    scanf("%d", &a[i]);
  for (int i = 0; i < k; i++)
    scanf("%d", &q[i]);
  for (int i = 0; i < n; i++) {
    bfr[i] = (i - 1 + n) % n;
    nxt[i] = (i + 1) % n;
    ans[i] = true;
  }
  int p = 0;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < a[i]; j++) {
      if (a[i] % 2 == 0)
        p = nxt[p];
      else
        p = bfr[p];
    }
    ans[p] = false;
    nxt[bfr[p]] = nxt[p];
    bfr[nxt[p]] = bfr[p];
    p = nxt[p];
  }
  for (int i = 0; i < k; i++)
    printf("%d\\n", ans[q[i]] ? 1 : 0);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
int N, M, Q;
int now;
void next() {
  now++;
  if (now == N)
    now = 0;
}
void before() {
  now--;
  if (now == -1)
    now = N - 1;
}
int main() {
  bool students[200000];
  cin >> N >> M >> Q;
  fill(students, students + N, true);
  int cnt;
  now = 0;
  for (int i = 0; i < M; i++) {
    int a;
    cin >> a;
    int b = a % (N - i);
    cnt = 0;
    while (1) {
      if (a % 2 == 0)
        next();
      else
        before();
      if (students[now]) {
        cnt++;
        if (cnt == b) {
          students[now] = false;
          next();
          break;
        }
      }
    }
  }
  for (int i = 0; i < Q; i++) {
    int q;
    cin >> q;
    cout << students[q] << endl;
  }
}
Problem p00296 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define fori(i, k, n) for (int i = k; i < (int)n; i++)
using namespace std;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
const int dX[8] = {0, 1, 1, 1, 0, -1, -1, -1},
          dY[8] = {1, 1, 0, -1, -1, -1, 0, 1};
/*
(char)'1' - (int)48 = (int)1;


*/
list<int> seito;
bool ans[200001] = {false};
int main() {
  int n, m, q;
  cin >> n >> m >> q;
  for (int i = 0; i < n; i++)
    seito.push_back(i);
  list<int>::iterator it = seito.begin();
  while (m--) {
    int x;
    cin >> x;
    if (x % 2 == 0) {
      for (int i = 0; i < x; i++) {
        it++;
        if (it == seito.end())
          it = seito.begin();
      }
    } else {
      for (int i = 0; i < x; i++) {
        if (it == seito.begin()) {
          it = seito.end();
          it--;
        } else {
          it--;
        }
      }
    }
    ans[*it] = true;
    if (it == seito.end()) {
      it = seito.erase(it);
      it = seito.begin();
    } else
      it = seito.erase(it);
    if (it == seito.end())
      it = seito.begin();
  }
  /*
  it = seito.begin();
  for (int i = 0; i < seito.size(); i++)
  {
          cout << *it << endl;
          it++;
  }
  */

  while (q--) {
    int x;
    cin >> x;
    if (ans[x])
      cout << 0 << endl;
    else
      cout << 1 << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define fori(i, k, n) for (int i = k; i < (int)n; i++)
using namespace std;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
const int dX[8] = {0, 1, 1, 1, 0, -1, -1, -1},
          dY[8] = {1, 1, 0, -1, -1, -1, 0, 1};
/*
(char)'1' - (int)48 = (int)1;


*/
vector<int> seito;
int main() {
  int n, m, q;
  cin >> n >> m >> q;
  for (int i = 0; i < n; i++)
    seito.push_back(i);

  int now = 0;
  while (m--) {
    int x;
    cin >> x;
    if (x % 2 == 1) {
      now -= x % seito.size();
      if (now < 0)
        now += seito.size();
      seito.erase(seito.begin() + now);
    } else {
      now += x % seito.size();
      if (now >= seito.size())
        now %= seito.size();
      seito.erase(seito.begin() + now);
    }
  }

  while (q--) {
    int x;
    cin >> x;
    if (binary_search(seito.begin(), seito.end(), x))
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
}
Problem p00296 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;

//// < "D:\\D_Download\\Visual Studio
///2015\\Projects\\programing_contest_c++\\Debug\\a.txt"
int main() {
  int N, M, Q;
  cin >> N >> M >> Q;
  vector<bool> oks(N);
  vector<pair<int, int>> moves(N);
  for (int i = 0; i < N; ++i) {
    moves[i] = make_pair((i + N - 1) % N, (i + 1) % N);
  }
  int now = 0;
  for (int i = 0; i < M; ++i) {
    int a;
    cin >> a;

    if (!(a % 2)) {
      for (int i = 0; i < a; ++i) {
        now = moves[now].second;
      }
      oks[now] = true;
    } else {
      for (int i = 0; i < a; ++i) {
        now = moves[now].first;
      }
      oks[now] = true;
    }
    moves[moves[now].first].second = moves[now].second;
    moves[moves[now].second].first = moves[now].first;
    now = moves[now].second;
  }
  for (int i = 0; i < Q; ++i) {
    int q;
    cin >> q;
    if (oks[q]) {
      cout << 0 << endl;
    } else {
      cout << 1 << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;

//// < "D:\\D_Download\\Visual Studio
///2015\\Projects\\programing_contest_c++\\Debug\\a.txt"
int main() {
  int N, M, Q;
  cin >> N >> M >> Q;
  vector<bool> oks(N);
  vector<pair<int, int>> moves(N);
  for (int i = 0; i < N; ++i) {
    moves[i] = make_pair((i + 1) % N, (i + N - 1) % N);
  }
  int now = 0;
  for (int i = 0; i < M; ++i) {
    int a;
    cin >> a;

    if (!(a % 2)) {
      a %= N - i;
      for (int i = 0; i < a; ++i) {
        while (oks[(now + 1) % N]) {
          now = (now + 1) % N;
        }
        now = (now + 1) % N;
      }

      oks[now] = true;
    } else {
      a %= N - i;
      for (int i = 0; i < a; ++i) {
        while (oks[(now + N - 1) % N]) {
          now = (now + N - 1) % N;
        }
        now = (now + N - 1) % N;
      }
      oks[now] = true;
    }
    while (oks[(now + 1) % N]) {
      now = (now + 1) % N;
    }
    now = (now + 1) % N;
  }
  for (int i = 0; i < Q; ++i) {
    int q;
    cin >> q;
    if (oks[q]) {
      cout << 0 << endl;
    } else {
      cout << 1 << endl;
    }
  }
  return 0;
}
Problem p00296 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N, M, Q;
  scanf("%d%d%d", &N, &M, &Q);
  list<int> v(N);
  iota(v.begin(), v.end(), 0);
  auto pos = v.begin();
  rep(i, M) {
    int a;
    scanf("%d", &a);
    if (a & 1) {
      rep(j, a) {
        if (pos == v.begin())
          pos = --v.end();
        else
          pos--;
      }
      if (pos == --v.end()) {
        v.pop_back();
        pos = v.begin();
      } else
        pos = v.erase(pos);
    } else {
      rep(j, a) {
        if (pos == --v.end())
          pos = v.begin();
        else
          pos++;
      }
      if (pos == --v.end()) {
        v.pop_back();
        pos = v.begin();
      } else
        pos = v.erase(pos);
    }
  }
  rep(i, Q) {
    int q;
    scanf("%d", &q);
    printf("%d\\n", binary_search(v.begin(), v.end(), q));
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int N, M, Q;
  scanf("%d%d%d", &N, &M, &Q);
  list<int> v(N);
  iota(v.begin(), v.end(), 0);
  int pos = 0;
  rep(i, M) {
    int a;
    scanf("%d", &a);
    if (a & 1) {
      auto it = v.begin();
      pos = (pos + v.size() * 20 - a) % v.size();
      for (int j = 0; j < pos; j++)
        it++;
      v.erase(it);
    } else {
      auto it = v.begin();
      pos = (pos + a) % v.size();
      for (int j = 0; j < pos; j++)
        it++;
      v.erase(it);
    }
  }
  rep(i, Q) {
    int q;
    scanf("%d", &q);
    printf("%d\\n", binary_search(v.begin(), v.end(), q));
  }
}
Problem p00296 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
 * 0301.cc: Baton Relay Game
 */

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

/* constant */

const int MAX_N = 200000;
const int MAX_M = 200000;

/* typedef */

struct Ring {
  int i;
  bool ng;
  struct Ring *l, *r;
};

/* global variables */

Ring rs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m, qn;
  cin >> n >> m >> qn;

  for (int i = 0; i < n; i++) {
    rs[i].i = i;
    rs[i].ng = false;
    rs[i].l = &rs[(i + n - 1) % n];
    rs[i].r = &rs[(i + 1) % n];
  }

  Ring *cpt = rs;
  int rn = n;

  for (int i = 0; i < m; i++) {
    int ai;
    cin >> ai;

    int maxj = ai % rn;
    if (ai & 1)
      for (int j = 0; j < ai; j++)
        cpt = cpt->l;
    else
      for (int j = 0; j < ai; j++)
        cpt = cpt->r;

    cpt->ng = true;
    cpt->l->r = cpt->r;
    cpt->r->l = cpt->l;
    cpt = cpt->r;
    rn--;
  }

  while (qn--) {
    int qi;
    cin >> qi;
    printf("%d\\n", rs[qi].ng ? 0 : 1);
  }

  return 0;
}

Error: TLE

Fixed submission:

/*
 * 0301.cc: Baton Relay Game
 */

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

/* constant */

const int MAX_N = 200000;
const int MAX_M = 200000;

/* typedef */

/* global variables */

bool rs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m, qn;
  cin >> n >> m >> qn;

  int pos = 0, rn = n;

  for (int i = 0; i < m; i++) {
    int ai;
    cin >> ai;

    int dp = (ai & 1) ? n - 1 : 1;
    ai %= rn;

    for (int j = 0; j < ai; j++) {
      for (pos = (pos + dp) % n; rs[pos]; pos = (pos + dp) % n)
        ;
    }

    rs[pos] = true;
    for (pos = (pos + 1) % n; rs[pos]; pos = (pos + 1) % n)
      ;
    rn--;
  }

  while (qn--) {
    int qi;
    cin >> qi;
    printf("%d\\n", rs[qi] ? 0 : 1);
  }

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

#include <stdio.h>
int prev[200000], next[200000];
int main() {
  int N, M, Q, a, q, p = 0, o;
  scanf("%d %d %d", &N, &M, &Q);
  for (int i = 0; i < N; i++) {
    prev[i] = (i - 1 + N) % N;
    next[i] = (i + 1) % N;
  }
  for (int i = 0; i < M; i++) {
    scanf("%d", &a);
    for (int j = 0; j < a; j++)
      p = a % 2 == 1 ? prev[p] : next[p];
    next[prev[p]] = next[p];
    prev[next[p]] = prev[p];
    o = next[p];
    prev[p] = -1;
    next[p] = -1;
    p = o;
  }
  for (int i = 0; i < Q; i++) {
    scanf("%d", &q);
    if (prev[q] == -1)
      printf("0\\n");
    else
      printf("1\\n");
  }
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
int main() {
  int N, M, Q, a, q, p = 0, o;
  int prev[100], next[100];
  scanf("%d %d %d", &N, &M, &Q);
  for (int i = 0; i < N; i++) {
    prev[i] = (i - 1 + N) % N;
    next[i] = (i + 1) % N;
  }
  for (int i = 0; i < M; i++) {
    scanf("%d", &a);
    for (int j = 0; j < a; j++)
      p = a % 2 == 1 ? prev[p] : next[p];
    next[prev[p]] = next[p];
    prev[next[p]] = prev[p];
    o = next[p];
    prev[p] = -1;
    next[p] = -1;
    p = o;
  }
  for (int i = 0; i < Q; i++) {
    scanf("%d", &q);
    if (prev[q] == -1)
      printf("0\\n");
    else
      printf("1\\n");
  }
  return 0;
}
Problem p00296 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iterator>
#include <set>
#include <stdio.h>
using namespace std;
int main() {
  int n, m, q, temp;
  set<int> s;
  set<int>::iterator now;
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < n; i++)
    s.insert(i);
  now = s.find(0);
  for (int i = 0; i < m; i++) {
    scanf("%d", &temp);
    if (temp % 2 == 0) {
      while (temp) {
        while (now != s.end()) {
          now++;
          temp--;
          if (temp == 0)
            break;
        }
        if (now == s.end())
          now = s.begin();
      }
    } else {
      while (temp) {
        while (now != s.begin()) {
          now--;
          temp--;
          if (temp == 0)
            break;
        }
        if (now == s.begin())
          now = s.end();
      }
      if (now == s.end())
        now = s.begin();
    }
    temp = *now;
    s.erase(now);
    now = s.lower_bound(temp);
  }
  while (q--) {
    scanf("%d", &temp);
    if (s.find(temp) == s.end())
      printf("0\\n");
    else
      printf("1\\n");
  }
}


Error: TLE

Fixed submission:

#include <iterator>
#include <set>
#include <stdio.h>
using namespace std;
int main() {
  int n, m, q, temp;
  set<int> s;
  set<int>::iterator now;
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < n; i++)
    s.insert(i);
  now = s.find(0);
  for (int i = 0; i < m; i++) {
    scanf("%d", &temp);
    if (temp & 1) {
      while (temp) {
        while (now != s.end()) {
          now++;
          temp--;
        }
        if (now == s.end())
          now = s.begin();
      }
    } else {
      while (temp) {
        while (now != s.begin()) {
          now--;
          temp--;
        }
        if (now == s.begin())
          now = s.end();
      }
      if (now == s.end())
        now = s.begin();
    }
    temp = *now;
    s.erase(now);
    now = s.lower_bound(temp);
  }
  while (q--) {
    scanf("%d", &temp);
    if (s.find(temp) == s.end())
      printf("0\\n");
    else
      printf("1\\n");
  }
}