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

#include <iostream>
#include <vector>

using namespace std;

class Record {
public:
  int t, n, m, s;
};

int compute_time(int s, int e, vector<Record> records) {
  int count = 0;
  int time = 0;
  int table[1261];
  for (int i = 0; i <= 1260; i++) {
    table[i] = 0;
  }
  for (int i = 0; i < (int)records.size(); i++) {
    table[records[i].t] += 2 * records[i].s - 1;
  }
  for (int i = 0; i <= 1260; i++) {
    count += table[i];
    if (count > 0 && s <= i && i < e) {
      time++;
    }
  }
  return time;
}

int main() {
  int n, m, r, q;
  while (true) {
    vector<Record> records[10001];
    cin >> n >> m;
    if (n == 0) {
      return 0;
    }
    for (int i = 0; i <= 10000; i++) {
      records[i].clear();
    }
    cin >> r;
    for (int i = 0; i < r; i++) {
      Record rec;
      cin >> rec.t >> rec.n >> rec.m >> rec.s;
      records[rec.m].push_back(rec);
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
      int s, e, m;
      cin >> s >> e >> m;
      cout << compute_time(s, e, records[m]) << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

class Record {
public:
  int t, n, m, s;
};

int compute_time(int s, int e, vector<Record> records) {
  int count = 0;
  int time = 0;
  int table[1260];
  for (int i = 0; i < 1260; i++) {
    table[i] = 0;
  }
  for (int i = 0; i < (int)records.size(); i++) {
    table[records[i].t] += 2 * records[i].s - 1;
  }
  for (int i = 0; i < 1260; i++) {
    count += table[i];
    if (count > 0 && s <= i && i < e) {
      time++;
    }
  }
  return time;
}

int main() {
  int n, m, r, q;
  while (true) {
    vector<Record> records[10000];
    cin >> n >> m;
    if (n == 0) {
      return 0;
    }
    for (int i = 0; i < 10000; i++) {
      records[i].clear();
    }
    cin >> r;
    for (int i = 0; i < r; i++) {
      Record rec;
      cin >> rec.t >> rec.n >> rec.m >> rec.s;
      records[rec.m].push_back(rec);
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
      int s, e, m;
      cin >> s >> e >> m;
      cout << compute_time(s, e, records[m]) << endl;
    }
  }
}
Problem p00729 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {

  int N, M, r;
  while (cin >> N >> M && !(N == 0 && M == 0)) {
    // Ô
    vector<pair<int, int>> Gakusei[10001];
    cin >> r;
    pair<int, int> pc[1001];
    for (int i = 0; i < r; i++) {
      int t;
      int n;
      int m;
      int s;
      cin >> t >> n >> m >> s;
      if (s == 1) {
        pc[n].first = t;
      } else {
        pc[n].second = t;
        Gakusei[m].push_back(pc[n]);
      }
    }

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
      int cnt = 0;
      int ts, te, m;
      cin >> ts >> te >> m;
      sort(Gakusei[m].begin(), Gakusei[m].end());
      int cTime = ts;
      for (int j = 0; j < Gakusei[m].size(); j++) {
        // æÃ~ÉJnÔª¢©ç©Ä¢­
        if (cTime >= Gakusei[m][j].second || Gakusei[m][j].first >= te)
          continue;
        else {
          cnt +=
              (min(te, Gakusei[m][j].second) - max(cTime, Gakusei[m][j].first));
          cTime = min(te, Gakusei[m][j].second);
        }
      }
      cout << cnt << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {

  int N, M, r;
  while (cin >> N >> M && !(N == 0 && M == 0)) {
    // Ô
    vector<pair<int, int>> Gakusei[1001];
    cin >> r;
    pair<int, int> pc[10001];
    for (int i = 0; i < r; i++) {
      int t;
      int n;
      int m;
      int s;
      cin >> t >> n >> m >> s;
      if (s == 1) {
        pc[n].first = t;
      } else {
        pc[n].second = t;
        Gakusei[m].push_back(pc[n]);
      }
    }

    int q;
    cin >> q;
    bool term[1261];
    for (int i = 0; i < q; i++) {
      fill(term, term + 1261, false);
      int cnt = 0;
      int ts, te, m;
      cin >> ts >> te >> m;

      sort(Gakusei[m].begin(), Gakusei[m].end());
      int cTime = ts;
      for (int j = 0; j < Gakusei[m].size(); j++) {
        // æÃ~ÉJnÔª¢©ç©Ä¢­

        if (cTime > Gakusei[m][j].second)
          continue;
        else {
          cnt +=
              (min(te, Gakusei[m][j].second) - max(cTime, Gakusei[m][j].first));
          cTime = Gakusei[m][j].second;
        }
      }
      cout << cnt << endl;
    }
  }
  return 0;
}
Problem p00729 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
using namespace std;

int S[10000][1261] = {};

int main() {
  int N, M, r, q, t, n, m, s, ts, te, time;

  while (1) {
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;
    for (int i = 0; i < M; i++) {
      for (int j = 0; j <= 1261; j++)
        S[i][j] = 0;
    }
    cin >> r;
    for (int i = 0; i < r; i++) {
      cin >> t >> n >> m >> s;
      if (s == 1)
        S[m - 1][t]++;
      else
        S[m - 1][t]--;
    }
    for (int i = 0; i < M; i++) {
      for (int j = 1; j <= 1261; j++) {
        S[i][j] += S[i][j - 1];
      }
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
      cin >> ts >> te >> m;
      time = 0;
      for (int j = ts; j < te; j++) {
        if (S[m - 1][j] > 0)
          time++;
      }
      cout << time << endl;
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;

int S[100][1261] = {};

int main() {
  int N, M, r, q, t, n, m, s, ts, te, time;

  while (1) {
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;
    for (int i = 0; i < M; i++) {
      for (int j = 0; j <= 1261; j++)
        S[i][j] = 0;
    }
    cin >> r;
    for (int i = 0; i < r; i++) {
      cin >> t >> n >> m >> s;
      if (s == 1)
        S[m - 1][t] = 1;
      else
        S[m - 1][t] = -1;
    }
    for (int i = 0; i < M; i++) {
      for (int j = 1; j <= 1261; j++) {
        S[i][j] += S[i][j - 1];
      }
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
      cin >> ts >> te >> m;
      time = 0;
      for (int j = ts; j < te; j++) {
        if (S[m - 1][j] > 0)
          time++;
      }
      cout << time << endl;
    }
  }
  return 0;
}
Problem p00729 (C++) — buggy submission, verdict: Runtime Error

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

struct Data {

  int s_cnt, e_cnt;
  int s_time[500], e_time[500];
};

int main() {

  int N, M;
  int r, q, t, n, m, m2, s;
  int t_s, t_e;
  int table[1000];

  while (1) {

    cin >> N >> M;
    if (N == 0 && M == 0)
      break;

    vector<Data> student(M + 1);

    for (int i = 0; i < M + 1; i++) {
      student[i].s_cnt = 0;
      student[i].e_cnt = 0;
    }

    cin >> r;
    for (int i = 0; i < r; i++) {
      cin >> t >> n >> m >> s;
      if (s == 1) {
        student[m].s_time[student[m].s_cnt] = t;
        student[m].s_cnt++;
      } else {
        student[m].e_time[student[m].e_cnt] = t;
        student[m].e_cnt++;
      }
    }

    cin >> q;
    for (int i = 0; i < q; i++) {
      cin >> t_s >> t_e >> m2;
      for (int j = 0; j < 1000; j++)
        table[j] = 0;
      for (int j = 0; j < student[m2].s_cnt; j++) {
        for (int k = student[m2].s_time[j] - 540;
             k < student[m2].e_time[j] - 540; k++) {
          table[k] = 1;
        }
      }
      int sum = 0;
      for (int j = t_s - 540; j < t_e - 540; j++)
        sum += table[j];
      cout << sum << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

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

typedef struct {

  int s_cnt, e_cnt;
  int s_time[1000], e_time[1000];

} Record;

int main() {

  int N, M;
  int r, q, t, n, m, m2, s;
  int t_s, t_e;
  int table[10000];

  while (1) {

    cin >> N >> M;
    if (N == 0 && M == 0)
      break;

    Record student[M + 1];

    for (int i = 0; i < M + 1; i++) {
      student[i].s_cnt = 0;
      student[i].e_cnt = 0;
    }

    cin >> r;
    for (int i = 0; i < r; i++) {
      cin >> t >> n >> m >> s;
      if (s == 1) {
        student[m].s_time[student[m].s_cnt] = t;
        student[m].s_cnt++;
      } else {
        student[m].e_time[student[m].e_cnt] = t;
        student[m].e_cnt++;
      }
    }

    cin >> q;
    for (int i = 0; i < q; i++) {
      cin >> t_s >> t_e >> m2;
      for (int j = 0; j < 10000; j++)
        table[j] = 0;
      for (int j = 0; j < student[m2].s_cnt; j++) {
        for (int k = student[m2].s_time[j]; k < student[m2].e_time[j]; k++) {
          table[k] = 1;
        }
      }
      int sum = 0;
      for (int j = t_s; j < t_e; j++)
        sum += table[j];
      cout << sum << endl;
    }
  }

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

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

#define rep2(i, b, n) for (int i = b; i < n; ++i)
#define rep(i, n) rep2(i, 0, n)
#define sz(x) x.size()
#define pb(x) push_back(x)
#define mk(x, y) make_pair(x, y)
#define B first
#define E second

using namespace std;

typedef pair<int, int> pii;

int cnt[10000];
vector<pii> v[10000];

bool used[1000];

int main(void) {
  int n, m;
  while (cin >> n >> m, n | m) {
    fill(cnt, cnt + 1000, 0);
    memset(used, false, sizeof(used));
    rep(i, m) v[i].clear();

    int r;
    cin >> r;
    rep(i, r) {
      int tt, nn, mm, ss;
      cin >> tt >> nn >> mm >> ss;
      --mm;
      if (ss) {
        if (used[nn])
          continue;
        if (cnt[mm] == 0) {
          v[mm].pb(mk(tt, 0));
        }
        ++cnt[mm];
        used[nn] = true;
      } else {
        if (!used[nn])
          continue;
        --cnt[mm];
        if (cnt[mm] == 0) {
          v[mm][sz(v[mm]) - 1].E = tt;
          // cout << v[mm][sz(v[mm])-1].B << ' ' << v[mm][sz(v[mm])-1].E <<
          // endl;
        }
        used[nn] = false;
      }
    }

    int q;
    cin >> q;
    rep(i, q) {
      int ts, te, mm, time;
      cin >> ts >> te >> mm;
      --mm;
      time = 0;
      rep(j, sz(v[mm])) {
        if ((ts <= v[mm][j].B && v[mm][j].B <= te) ||
            (ts <= v[mm][j].E && v[mm][j].E <= te) ||
            (v[mm][j].B <= ts && te <= v[mm][j].E)) {
          time += (min(te, v[mm][j].E) - max(ts, v[mm][j].B));
        }
      }
      cout << time << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

#define rep2(i, b, n) for (int i = b; i < n; ++i)
#define rep(i, n) rep2(i, 0, n)
#define sz(x) x.size()
#define pb(x) push_back(x)
#define mk(x, y) make_pair(x, y)
#define B first
#define E second

using namespace std;

typedef pair<int, int> pii;

int cnt[1000];
vector<pii> v[1000];

int main(void) {
  int n, m;
  while (cin >> n >> m, n | m) {
    fill(cnt, cnt + 1000, 0);
    rep(i, n) v[i].clear();

    int r;
    cin >> r;
    rep(i, r) {
      int tt, nn, mm, ss;
      cin >> tt >> nn >> mm >> ss;
      --mm;
      if (ss) {
        if (cnt[mm] == 0) {
          v[mm].pb(mk(tt, 0));
        }
        ++cnt[mm];
      } else {
        --cnt[mm];
        if (cnt[mm] == 0) {
          v[mm][sz(v[mm]) - 1].E = tt;
          // cout << v[mm][sz(v[mm])-1].B << ' ' << v[mm][sz(v[mm])-1].E <<
          // endl;
        }
      }
    }

    int q;
    cin >> q;
    rep(i, q) {
      int ts, te, mm, time;
      cin >> ts >> te >> mm;
      --mm;
      time = 0;
      rep(j, sz(v[mm])) {
        if ((ts <= v[mm][j].B && v[mm][j].B <= te) ||
            (ts <= v[mm][j].E && v[mm][j].E <= te) ||
            (v[mm][j].B <= ts && te <= v[mm][j].E)) {
          time += (min(te, v[mm][j].E) - max(ts, v[mm][j].B));
        }
      }
      cout << time << endl;
    }
  }
  return 0;
}
Problem p00729 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>

using namespace std;

#define NMAX 1000
#define tMAX 1260
int main(void) {

  int N, M;
  int r;
  int use[NMAX + 1][tMAX + 1];
  int t, n, m, s;
  int q;
  int ts, te;
  int cnt;
  bool f;

  while (1) {
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;

    for (int i = 1; i <= N; i++) {
      for (int j = 0; j <= tMAX; j++) {
        use[i][j] = 0;
      }
    }

    cin >> r;
    for (int i = 0; i < r; i++) {
      cin >> t >> n >> m >> s;
      if (s == 1)
        use[n][t] = m;
      else
        use[n][t] = -1 * m;
    }

    for (int i = 1; i <= N; i++) {
      for (int j = 1; j <= tMAX; j++) {
        use[i][j] += use[i][j - 1];
      }
    }

    cin >> q;

    for (int i = 0; i < q; i++) {
      cin >> ts >> te >> m;
      cnt = 0;
      for (int j = ts; j < te; j++) {
        f = false;
        for (int i = 1; i <= N; i++) {
          if (use[i][j] == m)
            f = true;
        }
        if (f)
          cnt++;
      }
      cout << cnt << endl;
    }
  }

  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

#define MMAX 10000
#define tMAX (60 * 24)

int main(void) {

  int N, M;
  int r;
  int t, n, m1, s;
  int q;
  int ts, te, m2;
  int num, cnt;
  int data[10][MMAX + 1][tMAX + 1];
  int nu = 0;

  while (cin >> N >> M) {
    if (N == 0 && M == 0)
      break;
    for (int i = 0; i <= MMAX; i++) {
      for (int j = 0; j <= tMAX; j++) {
        data[nu][i][j] = 0;
      }
    }
    cin >> r;

    for (int i = 0; i < r; i++) {
      cin >> t >> n >> m1 >> s;
      if (s == 0)
        data[nu][m1][t]--;
      else
        data[nu][m1][t]++;
    }

    for (int i = 1; i <= M; i++) {
      num = 0;
      for (int j = 0; j <= tMAX; j++) {
        num += data[nu][i][j];
        data[nu][i][j] = num;
      }
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
      cin >> ts >> te >> m2;
      cnt = 0;
      for (int j = ts; j < te; j++) {
        if (data[nu][m2][j] >= 1)
          cnt++;
      }
      cout << cnt << endl;
      nu++;
    }
  }
  return 0;
}
Problem p00729 (C++) — buggy submission, verdict: Runtime Error

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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define int long long
typedef pair<int, int> P;

//-----------------------------------------------------------------------

int N, M, R, Q;
int A[10000][1005]; // 生徒番号,時間

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (cin >> N >> M, N) {
    memset(A, 0, sizeof(A));
    cin >> R;
    REP(i, R) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      t -= 540;
      n--;
      m--;
      if (s)
        A[m][t]++;
      else
        A[m][t]--;
    }
    REP(i, M) {
      REP(j, 1000) { A[i][j + 1] += A[i][j]; }
    }
    cin >> Q;
    REP(i, Q) {
      int s, e, m;
      cin >> s >> e >> m;
      s -= 540;
      e -= 540;
      m--;
      int res = 0;
      for (int i = s; i < e; i++) {
        res += (A[m][i] >= 1);
      }
      cout << res << endl;
    }
  }
}


Error: 0

Fixed submission:

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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define int long long
typedef pair<int, int> P;

//-----------------------------------------------------------------------

int N, M, R, Q;
int A[1005][1005]; // 生徒番号,時間

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (cin >> N >> M, N) {
    memset(A, 0, sizeof(A));
    cin >> R;
    REP(i, R) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      t -= 540;
      n--;
      m--;
      if (s)
        A[m][t]++;
      else
        A[m][t]--;
    }
    REP(i, M) {
      REP(j, 1000) { A[i][j + 1] += A[i][j]; }
    }
    cin >> Q;
    REP(i, Q) {
      int s, e, m;
      cin >> s >> e >> m;
      s -= 540;
      e -= 540;
      m--;
      int res = 0;
      for (int i = s; i < e; i++) {
        res += (A[m][i] >= 1);
      }
      cout << res << endl;
    }
  }
}
Problem p00729 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <string.h>

int main(void) {
  int N, M, r, t, n, m, s, log[1000][721], q, ts, tg, i, j, k, flag[1000],
      count;
  ;
  while (1) {
    scanf("%d%d", &N, &M);
    if (N == 0 && M == 0)
      break;
    memset(log, 0, sizeof(log));
    scanf("%d", &r);
    for (i = 0; i < r; i++) {
      scanf("%d%d%d%d", &t, &n, &m, &s);
      if (s == 1)
        log[n - 1][t - 540] = m;
      else if (s == 0)
        log[n - 1][t - 540] = -1;
    }
    memset(flag, 0, sizeof(flag));
    for (i = 0; i < N; i++) {
      for (j = 0; j <= 720; j++) {
        if (log[i][j] && flag[i] == 0)
          flag[i] = log[i][j];
        else if (log[i][j] && flag[i] != 0)
          flag[i] = 0;
        if (flag[i] != 0)
          log[i][j] = flag[i];
      }
    }
    scanf("%d", &q);
    for (i = 0; i < q; i++) {
      scanf("%d%d%d", &ts, &tg, &m);
      memset(flag, 0, sizeof(flag));
      count = 0;
      for (j = ts - 540; j <= tg - 540; j++) {
        for (k = 0; k < N; k++) {
          if (flag[k]) {
            count++;
            break;
          }
        }
        for (k = 0; k < N; k++) {
          if (log[k][j] == m)
            flag[k] = 1;
          else if (log[k][j] != 0)
            flag[k] = 0;
        }
      }
      printf("%d\\n", count);
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
#include <string.h>

int main(void) {
  int N, M, r, t, n, m, s, log[17][721], q, ts, tg, i, j, k, flag[17], count;
  ;
  while (1) {
    scanf("%d%d", &N, &M);
    if (N == 0 && M == 0)
      break;
    memset(log, 0, sizeof(log));
    scanf("%d", &r);
    for (i = 0; i < r; i++) {
      scanf("%d%d%d%d", &t, &n, &m, &s);
      if (s == 1)
        log[n - 1][t - 540] = m;
      else if (s == 0)
        log[n - 1][t - 540] = -1;
    }
    memset(flag, 0, sizeof(flag));
    for (i = 0; i < N; i++) {
      for (j = 0; j <= 720; j++) {
        if (log[i][j] && flag[i] == 0)
          flag[i] = log[i][j];
        else if (log[i][j] && flag[i] != 0)
          flag[i] = 0;
        if (flag[i] != 0)
          log[i][j] = flag[i];
      }
    }
    scanf("%d", &q);
    for (i = 0; i < q; i++) {
      scanf("%d%d%d", &ts, &tg, &m);
      memset(flag, 0, sizeof(flag));
      count = 0;
      for (j = ts - 540; j <= tg - 540; j++) {
        for (k = 0; k < N; k++) {
          if (flag[k]) {
            count++;
            break;
          }
        }
        for (k = 0; k < N; k++) {
          if (log[k][j] == m)
            flag[k] = 1;
          else if (log[k][j] != 0)
            flag[k] = 0;
        }
      }
      printf("%d\\n", count);
    }
  }
  return 0;
}
Problem p00729 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <istream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef ostringstream oss;
typedef istringstream iss;

typedef vector<int> vi;
typedef vector<vi> vvi;

const int MIN_TIME = 540;
const int MAX_TIME = 1260;

bool isNotZero(int x) { return x; };

int main(void) {
  int pcNum, stuNum;
  while (cin >> pcNum >> stuNum, pcNum) {
    vvi recs(stuNum, vi(MAX_TIME - MIN_TIME + 1, 0));

    int recNum, queNum;
    cin >> recNum;
    for (int ri = 0; ri < recNum; ri++) {
      int time, pc, stu, type;
      cin >> time >> pc >> stu >> type;
      pc--;
      stu--;
      time -= MIN_TIME;
      if (type) {
        for (int i = time; i < recs[stu].size(); i++) {
          recs[stu][i] = recs[stu][i] + 1;
        }
      } else {
        for (int i = time; i < recs[stu].size(); i++) {
          recs[stu][i] = recs[stu][i] - 1;
        }
      }
    }

    cin >> queNum;
    for (int qi = 0; qi < queNum; qi++) {
      int start, end, stu;
      cin >> start >> end >> stu;
      stu--;
      start -= MIN_TIME;
      end -= MIN_TIME;

      int time = 0;
      time = count_if(recs[stu].begin() + start, recs[stu].begin() + end,
                      isNotZero);

      cout << time << endl;
    }
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <istream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef ostringstream oss;
typedef istringstream iss;

typedef vector<bool> vi;
typedef vector<vi> vvi;

const int MIN_TIME = 540;
const int MAX_TIME = 1260;

int main(void) {
  int pcNum, stuNum;
  while (cin >> pcNum >> stuNum, pcNum) {
    vector<vvi> recs(stuNum, vvi(pcNum, vi(MAX_TIME - MIN_TIME + 1, 0)));

    int recNum, queNum;
    cin >> recNum;
    for (int ri = 0; ri < recNum; ri++) {
      int time, pc, stu, type;
      cin >> time >> pc >> stu >> type;
      pc--;
      stu--;
      time -= MIN_TIME;
      if (type) {
        fill(recs[stu][pc].begin() + time, recs[stu][pc].end(), 1);
      } else {
        fill(recs[stu][pc].begin() + time, recs[stu][pc].end(), 0);
      }
    }

    for (int si = 0; si < stuNum; si++) {
      for (int pi = 0; pi < pcNum; pi++) {
        for (int ti = MAX_TIME - MIN_TIME; ti >= 0; ti--) {
          recs[si][0][ti] = max(recs[si][0][ti], recs[si][pi][ti]);
        }
      }
    }

    cin >> queNum;
    for (int qi = 0; qi < queNum; qi++) {
      int start, end, stu;
      cin >> start >> end >> stu;
      stu--;
      start -= MIN_TIME;
      end -= MIN_TIME;

      int time = 0;
      for (int ti = start; ti < end; ti++) {
        time += recs[stu][0][ti];
      }

      cout << time << endl;
    }
  }

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


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;
const int MAX_STUDENT = 10001;
const int MAX_TIME = 1261;
int main() {
  int N, M;
  while (true) {
    cin >> N >> M;
    if (!N)
      break;
    int r;
    cin >> r;
    vector<vector<int>> timeline(MAX_STUDENT, vector<int>(MAX_TIME, 0));
    REP(i, r) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      if (s == 0) {
        timeline[m][t] -= 1;
      } else {
        timeline[m][t] += 1;
      }
    }
    REP(i, MAX_STUDENT)
    for (int j = 540; j < MAX_TIME; j++) {
      timeline[i][j + 1] += timeline[i][j];
    }
    int q;
    cin >> q;

    REP(i, q) {
      int ct = 0;
      int t1, t2, m;
      cin >> t1 >> t2 >> m;
      for (int j = t1; j < t2; j++) {
        if (timeline[m][j] > 0)
          ct++;
      }
      cout << ct << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main() {
  int N, M;
  while (true) {
    cin >> N >> M;
    if (!N)
      break;
    int r;
    cin >> r;
    vector<vector<int>> timeline(1001, vector<int>(1300, 0));
    REP(i, r) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      if (s == 0) {
        timeline[m][t] -= 1;
      } else {
        timeline[m][t] += 1;
      }
    }
    REP(i, 1001)
    for (int j = 540; j < 1260; j++) {
      timeline[i][j + 1] += timeline[i][j];
    }
    int q;
    cin >> q;

    REP(i, q) {
      int ct = 0;
      int t1, t2, m;
      cin >> t1 >> t2 >> m;
      for (int j = t1; j < t2; j++) {
        if (timeline[m][j] > 0)
          ct++;
      }
      cout << ct << endl;
    }
  }
  return 0;
}