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

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#define INF 2000000000
using namespace std;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
#define ll long long
#define PL pair<long long, long long>
#define PR pair<int, int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;
#define int ll

// baton relay game
#define MAX 2000005

int remain[MAX];
int l[MAX], r[MAX];

signed main() {
  int n, m, q;
  cin >> n >> m >> q;
  for (int i = 0; i < n; i++) {
    remain[i] = true;
    l[i] = (n + i - 1) % n;
    r[i] = (i + 1) % n;
  }

  int now = 0;
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    if (a % 2) {
      for (int j = 0; j < a; j++)
        now = l[now];
      remain[now] = false;
      l[r[now]] = l[now];
      r[l[now]] = r[now];
      now = r[now];
    } else {
      for (int j = 0; j < a; j++)
        now = r[now];
      remain[now] = false;
      l[r[now]] = l[now];
      r[l[now]] = r[now];
      now = r[now];
    }
  }
  for (int i = 0; i < q; i++) {
    int Q;
    cin >> Q;
    if (remain[Q])
      cout << 1 << en else cout << 0 << en
  }

  RE
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#define INF 2000000000
using namespace std;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
#define ll long long
#define PL pair<long long, long long>
#define PR pair<int, int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;

// #define int ll

// baton relay game

#define MAX 200005
int students[MAX];
bool erased[MAX];

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

  list<int> li;
  for (int i = 0; i < n; i++) {
    erased[i] = false;
    li.push_back(i);
  }

  ll nowp = 0;

  for (int i = 0; i < m; i++) {
    int a;
    ll b;
    cin >> a;
    if (a % 2 == 0) {
      b = (nowp + a) % li.size();
    } else {
      a %= li.size();
      b = nowp - a;
      if (b < 0)
        b = nowp - a + li.size();
    }

    //    cout<<"b:      "<<b<<"            ";
    //    for(list<int>::iterator itr=li.begin(); itr!=li.end(); itr++) cout<<"
    //    "<<*itr; cout<<"              erased:   "<<*next(li.begin(),b)<<en

    li.erase(next(li.begin(), b));
    erased[*next(li.begin(), b)] = true;
    if (b == li.size() - 1) {
      //      cout<<"      hello"<<en
      nowp = 0;
    } else
      nowp = b;
  }

  //  cout<<en
  //  for(int i=0; i<n; i++){
  //    cout<<"   i:  "<<i<<"    ";
  //    if(erased[i]) cout<<0<<en
  //    else cout<<1<<en
  //  }

  for (int i = 0; i < q; i++) {
    int qq;
    cin >> qq;
    if (erased[qq])
      cout << 1 << en else cout << 0 << en
  }
  RE
}