Problem p00296 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef pair<int, pii> piii;
#define rrep(i, x, n) for (int i = (x); i < (n); ++i)
#define rep(i, x) rrep(i, 0, (x))
#define fi first
#define se second
#define each(i, c)                                                             \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define pb push_back
#define maxs(a, b) (a) = max(a, b)
#define mins(a, b) (a) = min(a, b)
/// #include<sstream>
/// #include<cstring>
/// #include<stack>
/// #include<complex>

bool flag[200000];
int prev[200000], next[200000];
int main() {
  int N, M, Q;
  scanf("%d%d%d", &N, &M, &Q);
  fill_n(flag, N, true);
  int pos = 0;
  rep(i, N) prev[i] = (i + N - 1) % N;
  rep(i, N) next[i] = (i + 1) % N;
  while (M--) {
    int a;
    scanf("%d", &a);
    if (a & 1)
      rep(i, a) pos = prev[pos];
    else
      rep(i, a) pos = next[pos];
    flag[pos] = false;
    next[prev[pos]] = next[pos];
    prev[next[pos]] = prev[pos];
    pos = next[pos];
  }
  while (Q--) {
    int q;
    scanf("%d", &q);
    puts((flag[q] ? "1" : "0"));
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef pair<int, pii> piii;
#define rrep(i, x, n) for (int i = (x); i < (n); ++i)
#define rep(i, x) rrep(i, 0, (x))
#define fi first
#define se second
#define each(i, c)                                                             \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define pb push_back
#define maxs(a, b) (a) = max(a, b)
#define mins(a, b) (a) = min(a, b)
/// #include<sstream>
/// #include<cstring>
/// #include<stack>
/// #include<complex>

bool flag[200000];

int main() {
  int N, M, Q;
  scanf("%d%d%d", &N, &M, &Q);
  fill_n(flag, N, true);
  int pos = 0;
  while (M--) {
    int a;
    scanf("%d", &a);
    if (a & 1) {
      while (a) {
        pos = (pos + N - 1) % N;
        if (!flag[pos])
          continue;
        a--;
      }
    } else {
      while (a) {
        pos = (pos + 1) % N;
        if (!flag[pos])
          continue;
        a--;
      }
    }
    flag[pos] = false;
    while (!flag[pos])
      pos = (pos + 1) % N;
  }

  while (Q--) {
    int q;
    scanf("%d", &q);
    puts((flag[q] ? "1" : "0"));
  }

  return 0;
}