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

#include <iostream>
#include <vector>

using namespace std;

class student {
public:
  int st[50], ed[50];
  int num, cnt;
  student() {
    num = 0;
    cnt = 0;
  }
};

int main() {
  int N; // PC数
  int M; // 学生数

  while (cin >> N >> M, N || M) {
    int r; // 利用記録数
    int q; // 質問数
    vector<student> std(M + 1);

    // 登録
    cin >> r;
    for (int i = 0; i < r; i++) {
      int t, n, m, s; // s(1: ログイン, 0: ログアウト), 時刻tにPCnで学生mが
      cin >> t >> n >> m >> s;

      if (s == 1) {            // ログイン
        if (std[m].cnt == 0) { // まだログインしていない
          std[m].st[std[m].num] = t;
        }
        std[m].cnt++;
      } else { // ログアウト
        if (std[m].cnt == 1)
          std[m].ed[std[m].num++] = t;
        std[m].cnt--;
      }
    }

    // 質問
    cin >> q;
    for (int i = 0; i < q; i++) {
      int ts, te, m;
      int ans = 0;

      cin >> ts >> te >> m;

      for (int j = 0; j < std[m].num; j++) {
        if (std[m].ed[j] <= ts)
          continue;
        if (std[m].st[j] >= te)
          break;

        if (std[m].st[j] <= ts && std[m].ed[j] >= te) {
          ans += te - ts;
          break;
        }
        if (std[m].st[j] <= ts && std[m].ed[j] < te)
          ans += std[m].ed[j] - ts;
        else if (std[m].st[j] >= ts && std[m].ed[j] >= te) {
          ans += te - std[m].st[j];
          break;
        } else if (std[m].st[j] >= ts && std[m].ed[j] < te)
          ans += std[m].ed[j] - std[m].st[j];
      }
      cout << ans << endl;
    }
  }

  return 0;
}

Error: -6
double free or corruption (!prev)


Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

class student {
public:
  int st[100], ed[100];
  int num, cnt;
  student() {
    num = 0;
    cnt = 0;
  }
};

int main() {
  int N; // 学生数
  int M; // PC数

  while (cin >> N >> M, N || M) {
    int r; // 利用記録数
    int q; // 質問数
    vector<student> std(N);

    // 登録
    cin >> r;
    for (int i = 0; i < r; i++) {
      int t, n, m, s; // s(1: ログイン, 0: ログアウト), 時刻tにPCnで学生mが
      cin >> t >> n >> m >> s;

      if (s == 1) {            // ログイン
        if (std[m].cnt == 0) { // まだログインしていない
          std[m].st[std[m].num] = t;
        }
        std[m].cnt++;
      } else { // ログアウト
        if (std[m].cnt == 1)
          std[m].ed[std[m].num++] = t;
        std[m].cnt--;
      }
    }

    // 質問
    cin >> q;
    for (int i = 0; i < q; i++) {
      int ts, te, m;
      int ans = 0;

      cin >> ts >> te >> m;

      for (int j = 0; j < std[m].num; j++) {
        if (std[m].ed[j] <= ts)
          continue;
        if (std[m].st[j] >= te)
          break;

        if (std[m].st[j] <= ts && std[m].ed[j] >= te) {
          ans += te - ts;
          break;
        }
        if (std[m].st[j] <= ts && std[m].ed[j] < te)
          ans += std[m].ed[j] - ts;
        else if (std[m].st[j] >= ts && std[m].ed[j] >= te) {
          ans += te - std[m].st[j];
          break;
        } else if (std[m].st[j] >= ts && std[m].ed[j] < te)
          ans += std[m].ed[j] - std[m].st[j];
      }
      cout << ans << endl;
    }
  }

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

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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (int i = a; i < int(b); i++)
#define rep(i, b) loop(i, 0, b)

struct event {
  int pc, time;
  bool login;
  event(int pc, int time, bool login) : pc(pc), time(time), login(login) {}
};

typedef vector<event> ve;
typedef vector<ve> vve;

vve es;

inline pair<int, int> intersection(int l1, int r1, int l2, int r2) {
  int l = max(l1, l2), r = min(r1, r2);
  return make_pair(l, r);
}

int main() {
  int N, M;
  while (cin >> N >> M && N | M) {
    es.assign(M + 1, {});
    int r;
    cin >> r;
    rep(i, r) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      es[m].emplace_back(n, t, s);
    }
    rep(i, M + 1) sort(all(es[i]), [](const event &a, const event &b) {
      return a.time < b.time;
    });
    int q;
    cin >> q;
    rep(i, q) {
      bool use[1260] = {};
      int ts, te, m;
      cin >> ts >> te >> m;
      int ans = 0;
      auto &e = es[m];
      rep(i, e.size()) {
        if (e[i].login) {
          int j = i + 1;
          while (e[i].pc != e[j].pc) {
            j++;
          }
          auto p = intersection(ts, te, e[i].time, e[j].time);
          loop(k, p.first, p.second) { use[k] = true; }
        }
      }
      rep(i, 1260) ans += use[i];
      cout << ans << endl;
    }
  }
}

Error: MLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <map>
#include <vector>

using namespace std;
#define loop(i, a, b) for (int i = (a); i < int(b); i++)
#define rep(i, b) loop(i, 0, b)

int main() {
  int N, M;
  while (scanf("%d%d", &N, &M) != EOF && N | M) {
    typedef pair<int, int> pii;
    typedef vector<pii> vp;
    typedef vector<vp> vvp;
    typedef vector<vvp> vvvp;
    vvvp v(N + 1, vvp(M + 1));
    int r;
    scanf("%d", &r);
    rep(i, r) {
      int t, n, m, s;
      scanf("%d%d%d%d", &t, &n, &m, &s);
      if (s) {
        v[n][m].emplace_back(t, 0);
      } else {
        v[n][m].back().second = t;
      }
    }

    int q;
    scanf("%d", &q);
    rep(i, q) {
      int s, e, m;
      int ans = 0;
      scanf("%d%d%d", &s, &e, &m);
      continue;
      static bool use[2000] = {};
      loop(j, 1, N + 1) rep(k, v[j][m].size()) {
        auto t = v[j][m][k];
        if (e < t.first || t.second < s)
          continue;
        int E = min(t.second, e);
        int S = max(t.first, s);
        if (S > E)
          continue;
        loop(w, S, E) use[w] = true;
        // printf("%d %d %d %d\\n",S,E,m,x);
      }
      rep(j, 2000) if (use[j]) ans++;
      cout << ans << endl;
    }
  }
}
Problem p00729 (C++) — buggy submission, verdict: Runtime Error


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define INF 1000000000
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long int ll;

int main() {
  for (;;) {
    int N, M;
    cin >> N >> M;
    if (!N and !M)
      break;
    int r;
    cin >> r;
    vector<int> g(10001 * 721, 0);
    map<ll, int> hoge;
    for (int i = 0; i < r; i++) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      t -= 540;
      if (s == 1) {
        hoge[1000 * m + n] = t;
      } else {
        for (int j = hoge[1000 * m + n]; j < t; j++) {
          g[m * 721 + j] = 1;
        }
      }
    }
    int q;
    cin >> q;
    for (int qq = 0; qq < q; qq++) {
      int ts, te, m, ans = 0;
      cin >> ts >> te >> m;
      for (int i = ts - 540; i < te - 540; i++) {
        if (g[m * 721 + i] == 1) {
          ans++;
        }
      }
      cout << ans << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define INF 1000000000
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long int ll;

int main() {
  for (;;) {
    int N, M;
    cin >> N >> M;
    if (!N and !M)
      break;
    int r;
    cin >> r;
    pair<int, int> g[1001][721];
    memset(g, 0, sizeof(g));
    for (int i = 0; i < r; i++) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      t -= 540;
      if (s == 1) {
        g[m][t] = {1, n};
      } else {
        g[m][t].first = 2;
        t--;
        while (t >= 0 and g[m][t].second != n) {
          g[m][t--].first = 1;
        }
      }
    }
    int q;
    cin >> q;
    for (int qq = 0; qq < q; qq++) {
      int ts, te, m, ans = 0;
      cin >> ts >> te >> m;
      for (int i = ts - 540; i < te - 540; i++) {
        if (g[m][i].first == 1) {
          ans++;
        }
      }
      cout << ans << endl;
    }
  }
}
Problem p00729 (C++) — buggy submission, verdict: Runtime Error

// Analyzing Login/Logout Records
#include <bits/stdc++.h>
using namespace std;

int pc[1000][721], st[10000][721];

int main() {
  int N, M;
  while (cin >> N >> M, !(N == 0 && M == 0)) {
    int r;
    memset(pc, 0, sizeof(pc));
    memset(st, 0, sizeof(st));
    cin >> r;
    while (r--) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      pc[n - 1][t - 540] = m;
      if (s == 0) {
        st[m - 1][t - 540] = 1;
        t--;
        while (true) {
          st[m - 1][t - 540] = 1;
          if (pc[n - 1][t - 540] == m || t - 540 == 0)
            break;
          t--;
        }
      }
    }
    int q;
    cin >> q;
    while (q--) {
      int ts, te, m;
      cin >> ts >> te >> m;
      int cnt = 0;
      bool flag = false;
      for (int i = ts - 540; i <= te - 540; i++) {
        if (st[m - 1][i] == 1 && flag)
          cnt++;
        if (st[m - 1][i] == 1)
          flag = true;
        else
          flag = false;
      }
      cout << cnt << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

// Analyzing Login/Logout Records
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  while (cin >> N >> M, !(N == 0 && M == 0)) {
    int pc[N][721], st[M][721], r;
    memset(pc, 0, sizeof(pc));
    memset(st, 0, sizeof(st));
    cin >> r;
    while (r--) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      pc[n - 1][t - 540] = m;
      if (s == 0) {
        st[m - 1][t - 540] = 1;
        t--;
        while (true) {
          st[m - 1][t - 540] = 1;
          if (pc[n - 1][t - 540] == m || t - 540 == 0)
            break;
          t--;
        }
      }
    }
    int q;
    cin >> q;
    while (q--) {
      int ts, te, m;
      cin >> ts >> te >> m;
      int cnt = 0;
      bool flag = false;
      for (int i = ts - 540; i <= te - 540; i++) {
        if (st[m - 1][i] == 1 && flag)
          cnt++;
        if (st[m - 1][i] == 1)
          flag = true;
        else
          flag = false;
      }
      cout << cnt << endl;
    }
  }
  return 0;
}
Problem p00729 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int N, M;
  while (cin >> N >> M && N != 0 || M != 0) {
    int r;
    cin >> r;
    static int timeLine[10000 + 1][24 * 60 - 540];
    static int pcNumber[1000 + 1];
    for (int i = 0; i < M + 1; i++) {
      for (int j = 0; j < 24 * 60 - 540; j++) {
        timeLine[i][j] = 0;
      }
    }

    for (int i = 0; i < r; i++) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      if (s == 1) {
        pcNumber[n] = t;
      } else {
        for (int j = pcNumber[n] - 540; j < t - 540; j++) {
          timeLine[m][j] = 1;
        }
      }
    }

    int q;
    cin >> q;

    for (int i = 0; i < q; i++) {
      int start, end, m;
      cin >> start >> end >> m;
      int ans = 0;
      for (int j = start - 540; j < end - 540; j++) {
        if (timeLine[m][j] == 1) {
          ans++;
        }
      }

      cout << ans << endl;
    }
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int N, M;
  while (cin >> N >> M && N != 0 || M != 0) {
    int r;
    cin >> r;
    static int timeLine[10000 + 1][24 * 60 - 540];
    static int startTime[1000 + 1][10000 + 1];
    for (int i = 0; i < M + 1; i++) {
      for (int j = 0; j < 24 * 60 - 540; j++) {
        timeLine[i][j] = 0;
      }
    }

    for (int i = 0; i < r; i++) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      if (s == 1) {
        startTime[n][m] = t;
      } else {
        for (int j = startTime[n][m] - 540; j < t - 540; j++) {
          timeLine[m][j] = 1;
        }
      }
    }

    int q;
    cin >> q;

    for (int i = 0; i < q; i++) {
      int start, end, m;
      cin >> start >> end >> m;
      int ans = 0;
      for (int j = start - 540; j < end - 540; j++) {
        if (timeLine[m][j] == 1) {
          ans++;
        }
      }

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

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

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

class history {
public:
  int pc, start, end;
  history(int p, int s, int e) {
    pc = p;
    start = s;
    end = e;
  }
};

int main(void) {
  vector<history> hist[10010];
  int N, M;
  int r, t, n, m, s, q, ts, te;
  int imos[1265];
  while (cin >> N >> M && N) {
    rep(i, 10010) hist[i].clear();
    cin >> r;
    rep(i, r) {
      cin >> t >> n >> m >> s;
      if (s == 1) {
        hist[m].push_back(history(n, t, -1));
      } else {
        rep(j, hist[m].size()) {
          if (hist[m][j].pc == n && hist[m][j].end == -1) {
            hist[m][j].end = t;
            break;
          }
        }
      }
    }
    cin >> q;
    rep(i, q) {
      cin >> ts >> te >> m;
      rep(j, 1265) imos[j] = 0;
      rep(j, hist[m].size()) {
        if (hist[m][j].start < te && hist[m][j].end > ts) {
          imos[max(hist[m][j].start, ts)] += 1;
          imos[min(hist[m][j].end, te)] -= 1;
        }
      }
      int ans = 0;
      int cnt = 0;
      int start;
      rep(j, 1265) {
        if (cnt == 0 && imos[j] > 0) {
          start = j;
        }
        if (cnt > 0 && cnt + imos[j] == 0) {
          ans += (j - start);
        }
        cnt += imos[j];
      }
      cout << ans << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

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

class history {
public:
  int pc, start, end;
  history(int p, int s, int e) {
    pc = p;
    start = s;
    end = e;
  }
};
int main(void) {
  int N, M;
  int r, t, n, m, s, ts, te, q;
  vector<history> hist[1001];
  while (cin >> N >> M && N) {
    rep(i, 1001) hist[i].clear();
    cin >> r;
    rep(i, r) {
      cin >> t >> n >> m >> s;
      n--;
      m--;
      if (s == 1) {
        hist[m].push_back(history(n, t, -1));
      } else {
        rep(j, hist[m].size()) {
          if (hist[m][j].pc == n && hist[m][j].end == -1) {
            hist[m][j].end = t;
            break;
          }
        }
      }
    }
    cin >> q;
    rep(i, q) {
      int ans = 0;
      cin >> ts >> te >> m;
      m--;
      int tmp[1265];
      rep(j, 1265) tmp[j] = 0;
      rep(j, hist[m].size()) {
        if (hist[m][j].end >= ts && hist[m][j].start <= te) {
          for (int t = max(ts, hist[m][j].start); t <= min(te, hist[m][j].end);
               ++t)
            tmp[t] = 1;
        }
      }
      for (int j = 540; j < 1265; j++) {
        int state = 0;
        if (tmp[j] == 1) {
          int start = j;
          while (tmp[j] == 1)
            j++;
          ans += j - start - 1;
        }
      }
      cout << ans << endl;
    }
  }
}
Problem p00729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int, int>
#define PLL pair<ll, ll>
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define RFOR(i, m, n) for (int i = m; i >= n; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define all(a) a.begin(), a.end()
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};
#define PI 3.14159265

int e[11000][1300];

void f(int n, int m) {
  rep(i, 11000) {
    rep(j, 1300) { e[i][j] = 0; }
  }
  int r;
  cin >> r;
  while (r-- > 0) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (d == 1) {
      e[c][a + 1]++;
    } else {
      e[c][a + 1]--;
    }
  }
  rep(i, 11000) {
    FOR(j, 1, 1300) { e[i][j] += e[i][j - 1]; }
    FOR(j, 1, 1300) {
      e[i][j] = (e[i][j] > 0);
      e[i][j] += e[i][j - 1];
    }
  }

  int q;
  cin >> q;
  while (q-- > 0) {
    int a, b, c;
    cin >> a >> b >> c;
    int ans = e[c][b] - e[c][a];
    cout << ans << endl;
  }
}

int main() {
  while (1) {
    int n, m;
    cin >> n >> m;
    if (n == 0)
      break;
    f(n, m);
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int, int>
#define PLL pair<ll, ll>
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define RFOR(i, m, n) for (int i = m; i >= n; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define all(a) a.begin(), a.end()
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};
#define PI 3.14159265

void f(int n, int m) {
  int v[1300][1100] = {};
  bool e[1300] = {};
  int r;
  cin >> r;
  rep(i, r) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    e[c] = true;
    if (d == 1) {
      v[c][a]++;
    }
    if (d == 0) {
      v[c][a]--;
    }
  }

  rep(i, 1300) {
    if (!e[i])
      continue;
    FOR(j, 540, 1100) { v[i][j] += v[i][j - 1]; }
    FOR(j, 540, 1100) {
      v[i][j] = (v[i][j] > 0);
      v[i][j] += v[i][j - 1];
    }
  }

  int q;
  cin >> q;
  rep(i, q) {
    int a, b, c;
    cin >> a >> b >> c;
    cout << v[c][b - 1] - v[c][a - 1] << endl;
  }
}

int main() {
  while (1) {
    int n, m;
    cin >> n >> m;
    if (n == 0)
      break;
    f(n, m);
  }

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

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

#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) REP(i, 0, n)
#define INF (1 << 30)
#define INFLL (1LL << 62LL)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  while (cin >> N >> M, N && M) {
    int r, q;
    vector<vector<int>> record(M, vector<int>(1261, 0));

    cin >> r;
    rep(i, r) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      n--;
      m--;
      if (s)
        record[m][t]++;
      else
        record[m][t]--;
    }

    rep(i, M) rep(t, 1261) if (t) record[i][t] += record[i][t - 1];

    cin >> q;
    rep(i, q) {
      int ts, te, m;
      cin >> ts >> te >> m;
      m--;

      int ans = 0;
      REP(t, ts, te) ans += (record[m][t] != 0);
      cout << ans << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

const double pi = 2 * acos(0.0);
const double eps = 1e-8;

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int Cost;
struct Edge {
  int src, dst;
  Cost cost;
  Edge(int s, int d, Cost c) : src(s), dst(d), cost(c) {}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Cost> Array;
typedef vector<Array> Matrix;

int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};

int pc_start_time[1000];
short time_flow[1000][761];

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  while (cin >> N >> M, N || M) {
    for (int i = 0; i < 1000; i++)
      pc_start_time[i] = -1;
    rep(i, 1000) rep(j, 761) time_flow[i][j] = 0;

    int r, q;
    cin >> r;
    for (int i = 0; i < r; i++) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      t -= 540;
      n--;
      m--;
      if (s == 0) {
        for (int j = pc_start_time[n]; j < t; j++)
          time_flow[m][j] = 1;
      } else {
        pc_start_time[n] = t;
      }
    }

    cin >> q;
    for (int i = 0; i < q; i++) {
      int ts, te, m;
      cin >> ts >> te >> m;
      ts -= 540;
      te -= 540;
      m--;
      int ans = 0;
      for (int j = ts; j < te; j++)
        if (time_flow[m][j] == 1)
          ans += 1;
      cout << ans << endl;
    }
  }
  return 0;
}
Problem p00729 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

typedef pair<int, int> P;

vector<P> p[10001];
int c[10001][2];
int N, M, R, Q;

int main() {
loop:
  for (int i = 0; i < 10001; i++) {
    c[i][0] = -1;
    c[i][1] = 0;
    p[i].clear();
  }
  cin >> N >> M;
  if (!N)
    return 0;
  cin >> R;
  for (int i = 0; i < R; i++) {
    int t, n, m, s;
    cin >> t >> n >> m >> s;
    if (s) {
      if (c[m][0] == -1)
        c[m][0] = t;
      c[m][1]++;
    } else {
      if (!(--c[m][1])) {
        p[m].push_back(make_pair(c[m][0], t));
        c[m][0] = -1;
      }
    }
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int ts, te, m, a = 0;
    cin >> ts >> te >> m;
    for (auto e : p[m]) {
      if (e.second < ts || te < e.first)
        continue;
      if (ts <= e.first && e.second <= te)
        a += e.second - e.first;
      else if (ts <= e.first)
        a += te - e.first;
      else if (e.second <= te)
        a += e.second - ts;
      else
        a += te - ts;
    }
    cout << a << endl;
  }
  goto loop;
}

Error: MLE

Fixed submission:

#include <iostream>

using namespace std;

int cnt[10001][1261], sum[10001][1261], N, M, R, Q;
int main() {
loop:;
  fill((int *)cnt, (int *)cnt + 10001 * 1261, 0);
  fill((int *)sum, (int *)sum + 10001 * 1261, 0);
  cin >> N >> M;
  if (!N)
    return 0;
  cin >> R;
  for (int i = 0; i < R; i++) {
    int t, n, m, s;
    cin >> t >> n >> m >> s;
    if (s)
      cnt[m][t]++;
    else
      cnt[m][t]--;
  }
  for (int m = 1; m <= M; m++) {
    sum[m][0] = cnt[m][0] ? 1 : 0;
    for (int i = 1; i <= 1260; i++) {
      cnt[m][i] = cnt[m][i - 1] + cnt[m][i];
      sum[m][i] = sum[m][i - 1] + (cnt[m][i] ? 1 : 0);
    }
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int ts, te, m;
    cin >> ts >> te >> m;
    cout << sum[m][te - 1] - sum[m][ts - 1] << endl;
  }
  goto loop;
}
Problem p00729 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>

using namespace std;
typedef pair<int, int> pii;

int main() {

  while (1) {
    int N, M;
    cin >> N >> M;
    if (!(N || M))
      break;
    int r;
    cin >> r;

    int t[r], n[r], m[r], s[r];
    for (int i = 0; i < r; i++) {
      cin >> t[i] >> n[i] >> m[i] >> s[i];
      m[i]--;
    }
    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
      int ss, ee, mm;
      cin >> ss >> ee >> mm;
      mm--;
      int a[1270] = {};
      for (int i = 0; i < r; i++) {
        if (m[i] == mm) {
          if (s[i])
            a[t[i]] += 1;
          else
            a[t[i]] -= 1;
        }
      }
      for (int i = 1; i < 1270; i++) {
        a[i] += a[i - 1];
      }
      int k = 0;
      for (int j = ss; j < ee; j++) {
        k += (a[j] > 0);
      }
      cout << k << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>

using namespace std;
typedef pair<int, int> pii;

int main() {

  while (1) {
    int N, M;
    cin >> N >> M;
    if (!(N || M))
      break;
    int r;
    cin >> r;

    int a[M][1270];
    for (int i = 0; i < M; i++) {
      for (int j = 0; j < 1270; j++) {
        a[i][j] = 0;
      }
    }
    for (int i = 0; i < r; i++) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      n--;
      m--;
      if (s) {
        a[m][t] += 1;
      } else {
        a[m][t] -= 1;
      }
    }
    for (int i = 0; i < M; i++) {
      for (int j = 1; j < 1270; j++) {
        a[i][j] += a[i][j - 1];
      }
    }

    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
      int s, e, m;
      cin >> s >> e >> m;
      m--;
      int k = 0;
      for (int j = s; j < e; j++) {
        k += (a[m][j] > 0);
      }
      cout << k << endl;
    }
  }

  return 0;
}