alexjercan/bugnet huggingface dataset:
Problem p00729 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair

template <class T> void pv(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << *i << " ";
  cout << endl;
}
template <class T> void chmin(T &t, T f) {
  if (t > f)
    t = f;
}
template <class T> void chmax(T &t, T f) {
  if (t < f)
    t = f;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

int login[10100][1261];

int main() {
  int N, M;
  while (cin >> N >> M, N) {
    int r, q;
    cin >> r;
    int i;
    memset(login, 0, sizeof(login));
    for (i = 0; i < r; i++) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      login[m][t] += (s ? 1 : -1);
    }
    int j;
    int l;
    for (j = 0; j <= M; j++) {
      l = 0;
      for (i = 540; i <= 1260; i++) {
        l += login[j][i];
        login[j][i] = l;
        // cout<<j<<" "<<i<<" "<<l<<endl;
      }
    }
    cin >> q;
    for (i = 0; i < q; i++) {
      int ts, te, m;
      cin >> ts >> te >> m;
      int res = 0;
      for (j = ts; j < te; j++) {
        if (login[m][j] > 0)
          res++;
      }
      cout << res << endl;
    }
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair

template <class T> void pv(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << *i << " ";
  cout << endl;
}
template <class T> void chmin(T &t, T f) {
  if (t > f)
    t = f;
}
template <class T> void chmax(T &t, T f) {
  if (t < f)
    t = f;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

int login[10100][2000];

int main() {
  int N, M;
  while (cin >> N >> M, N) {
    int r, q;
    cin >> r;
    int i;
    memset(login, 0, sizeof(login));
    for (i = 0; i < r; i++) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      login[m][t] += (s ? 1 : -1);
    }
    int j;
    int l;
    for (j = 0; j <= M; j++) {
      l = 0;
      for (i = 540; i <= 1260; i++) {
        l += login[j][i];
        login[j][i] = l;
        // cout<<j<<" "<<i<<" "<<l<<endl;
      }
    }
    cin >> q;
    for (i = 0; i < q; i++) {
      int ts, te, m;
      cin >> ts >> te >> m;
      int res = 0;
      for (j = ts; j < te; j++) {
        if (login[m][j] > 0)
          res++;
      }
      cout << res << endl;
    }
  }
  return 0;
}
Problem p00729 (C++) — buggy submission, verdict: Memory Limit Exceeded

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge {
  int u, v;
  ll w;
};

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  for (;;) {
    int N, M;
    cin >> N >> M;
    if (N == 0)
      break;
    vector<vector<short>> a(M, vector<short>(1300));
    int r;
    cin >> r;
    while (r--) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      m--;
      a[m][t] += (s ? 1 : -1);
    }
    vector<vector<short>> s(M, vector<short>(1300));
    for (int m = 0; m < M; m++)
      for (int t = 1; t < 1300; t++)
        s[m][t] = s[m][t - 1] + a[m][t - 1];
    int q;
    cin >> q;
    while (q--) {
      int ts, te, m;
      cin >> ts >> te >> m;
      m--;
      int cnt = 0;
      for (int t = ts + 1; t <= te; t++)
        if (s[m][t])
          cnt++;
      cout << cnt << endl;
    }
  }
}

Error: MLE

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge {
  int u, v;
  ll w;
};

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  for (;;) {
    int N, M;
    cin >> N >> M;
    if (N == 0)
      break;
    vector<vector<int>> a(M, vector<int>(1300));
    int r;
    cin >> r;
    while (r--) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      m--;
      a[m][t] += (s ? 1 : -1);
    }
    vector<vector<int>> s(M, vector<int>(1300));
    for (int m = 0; m < M; m++)
      for (int t = 1; t < 1300; t++)
        s[m][t] = s[m][t - 1] + a[m][t - 1];
    int q;
    cin >> q;
    while (q--) {
      int ts, te, m;
      cin >> ts >> te >> m;
      m--;
      int cnt = 0;
      for (int t = ts + 1; t <= te; t++)
        if (s[m][t])
          cnt++;
      cout << cnt << endl;
    }
  }
}
Problem p00729 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
enum { LOGOUT, LOGIN };
const int MAX_T = 1260 + 1 - 540;
int tomin(int d) { return d - 540; }
bool table[10000 + 1][MAX_T];
int login[1000 + 1];

int main() {
  int N, M;
  while (cin >> N >> M, N || M) {
    int r;
    cin >> r;
    for (int i = 0; i < M + 1; i++) {
      for (int j = 0; j < MAX_T; j++) {
        table[i][j] = false;
      }
    }
    for (int i = 0; i < r; i++) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      t = tomin(t);
      switch (s) {
      case LOGIN:
        login[n] = t;
        break;
      case LOGOUT:
        fill(&table[m][login[n]], &table[m][t], true);
        break;
      }
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
      int ts, te, m;
      cin >> ts >> te >> m;
      ts = tomin(ts);
      te = tomin(te);
      cout << count(&table[m][ts], &table[m][te], true) << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
enum { LOGOUT, LOGIN };
const int MAX_T = 1260 + 1 - 540;
int tomin(int d) { return d - 540; }

int main() {
  int N, M;
  while (cin >> N >> M, N || M) {
    int r;
    cin >> r;
    bool table[M + 1][MAX_T];
    for (int i = 0; i < M + 1; i++) {
      for (int j = 0; j < MAX_T; j++) {
        table[i][j] = false;
      }
    }
    int login[M + 1][N];
    for (int i = 0; i < r; i++) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      t = tomin(t);
      switch (s) {
      case LOGIN:
        login[m][n] = t;
        break;
      case LOGOUT:
        fill(&table[m][login[m][n]], &table[m][t], true);
        break;
      }
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
      int ts, te, m;
      cin >> ts >> te >> m;
      ts = tomin(ts);
      te = tomin(te);
      cout << count(&table[m][ts], &table[m][te], true) << endl;
    }
  }
}
Problem p00729 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
bool table[10001][1261];

int main() {
  int N, M;
  while (cin >> N >> M, N || M) {
    int lastin[N + 1];
    int r;
    memset(table, 0, sizeof(table));
    cin >> r;
    for (int i = 0; i < r; i++) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      if (s) {
        lastin[n] = t;
      } else {
        fill(table[m] + lastin[n], table[m] + t, true);
      }
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
      int s, e, m;
      cin >> s >> e >> m;
      cout << count(table[m] + s, table[m] + e, true) << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int N, M;
  while (cin >> N >> M, N || M) {
    bool table[M + 1][1261];
    int lastin[N + 1];
    int r;
    memset(table, 0, sizeof(table));
    cin >> r;
    for (int i = 0; i < r; i++) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      if (s) {
        lastin[n] = t;
      } else {
        fill(table[m] + lastin[n], table[m] + t, true);
      }
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
      int s, e, m;
      cin >> s >> e >> m;
      cout << count(table[m] + s, table[m] + e, true) << endl;
    }
  }
  return 0;
}
Problem p00729 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
using namespace std;
struct student {
  int start[1000];
  bool used[721];
};
student S[10000];
int main() {
  int N, M;
  while (cin >> N >> M) {
    if (N == 0)
      break;
    int r, q;
    memset(S, 0, sizeof(S));
    cin >> r;
    for (int i = 0; i < r; i++) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      t -= 540;
      m--;
      if (s == 1) {
        S[m].start[n] = t;
      } else {
        while (t > 0 && S[m].start[n] < t)
          S[m].used[--t] = true;
      }
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
      int ts, te, m, ans = 0;
      cin >> ts >> te >> m;
      ts -= 540;
      te -= 540;
      m--;
      for (int i = ts; i < te; i++) {
        if (S[m].used[i] == true)
          ans++;
      }
      cout << ans << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
int student[10000][721];
int main() {
  int N, M;
  while (cin >> N >> M) {
    if (N == 0)
      break;
    int r, q;
    memset(student, -1, sizeof(student));
    cin >> r;
    for (int i = 0; i < r; i++) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      t -= 540;
      m--;
      if (s == 1) {
        student[m][t] = n;
      } else {
        while (student[m][--t] != n)
          if (student[m][t] <= 0)
            student[m][t] = n;
      }
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
      int ts, te, m, ans = 0;
      cin >> ts >> te >> m;
      ts -= 540;
      te -= 540;
      m--;
      for (int i = ts; i < te; i++) {
        if (student[m][i] > 0)
          ans++;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
Problem p00729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define MOD 1000000007
#define ADD(X, Y) ((X) = ((X) + (Y) % MOD) % MOD)
typedef long long i64;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef pair<int, int> pi;
int dd[] = {0, 1, 0, -1, 0};
#define all(u) begin(u), end(u)
#define mp make_pair
#define pb push_back

int A[10010][1500];
int main() {
  while (true) {
    int N, M;
    scanf("%d%d", &N, &M);
    if (N == 0 && M == 0)
      break;
    // int A[10010][1500]={0};
    // int A[10010][1500];
    memset(A, 0, sizeof(A));
    int r;
    scanf("%d", &r);
    rep(i, r) {
      int t, n, m, s;
      scanf("%d%d%d%d", &t, &n, &m, &s);
      if (s == 1) {
        A[m][t]++;
      } else {
        A[m][t + 1]--;
      }
    }
    repi(i, 1, M + 1) {
      rep(t, 1300) {
        if (t == 0)
          continue;
        A[i][t] += A[i][t - 1];
      }
    }

    int q;
    scanf("%d", &q);
    rep(i, q) {
      int ts, te, m;
      scanf("%d%d%d", &ts, &te, &m);
      int start = -1;
      int ans = 0;
      repi(t, ts, te + 1) {
        if (start == -1) {
          if (A[m][t] > 0) {
            start = t;
          }
        } else {
          if (A[m][t] <= 0) {
            ans += t - start - 1;
            start = -1;
          }
        }
      }
      if (start != -1)
        ans += te - start;
      printf("%d\\n", ans);
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define MOD 1000000007
#define ADD(X, Y) ((X) = ((X) + (Y) % MOD) % MOD)
typedef long long i64;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef pair<int, int> pi;
int dd[] = {0, 1, 0, -1, 0};
#define all(u) begin(u), end(u)
#define mp make_pair
#define pb push_back

int main() {
  while (true) {
    int N, M;
    scanf("%d%d", &N, &M);
    if (N == 0 && M == 0)
      break;
    // int A[10010][1500]={0};
    int A[10010][1500];
    memset(A, 0, sizeof(A));
    int r;
    scanf("%d", &r);
    rep(i, r) {
      int t, n, m, s;
      scanf("%d%d%d%d", &t, &n, &m, &s);
      if (s == 1) {
        A[m][t]++;
      } else {
        A[m][t + 1]--;
      }
    }
    repi(i, 1, M + 1) {
      rep(t, 1300) {
        if (t == 0)
          continue;
        A[i][t] += A[i][t - 1];
      }
    }

    int q;
    scanf("%d", &q);
    rep(i, q) {
      int ts, te, m;
      scanf("%d%d%d", &ts, &te, &m);
      int start = -1;
      int ans = 0;
      repi(t, ts, te + 1) {
        if (start == -1) {
          if (A[m][t] > 0) {
            start = t;
          }
        } else {
          if (A[m][t] <= 0) {
            ans += t - start - 1;
            start = -1;
          }
        }
      }
      if (start != -1)
        ans += te - start;
      printf("%d\\n", ans);
    }
  }
  return 0;
}
Problem p00729 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdio.h>
using namespace std;

int n[10001][723] = {};
int main() {

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

    for (int i = 0; i <= M; i++)
      for (int j = 0; j < 722; j++)
        n[i][j] = 0;

    for (int i = 0; i < r; i++) {
      int t, x, m, w;
      cin >> t >> x >> m >> w;
      t -= 540;
      if (w == 1)
        n[m][t] += 1;
      else {
        n[m][t] -= 1;
      }
    }
    for (int i = 0; i <= M; i++)
      for (int j = 0; j < 721; j++)
        n[i][j + 1] += n[i][j];

    int q, t1, t2, y;
    cin >> q;

    for (int i = 0; i < q; i++) {
      cin >> t1 >> t2 >> y;
      t1 -= 540;
      t2 -= 540;
      int c = 0;
      for (int j = t1; j < t2; j++) {
        if (n[y][j] != 0) {
          c++;
        } // cout<<j+540<<" "<<c<<n[y][j]<<endl;}
      }
      cout << c << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;

int n[1001][723] = {};
int main() {

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

    for (int i = 0; i <= M; i++)
      for (int j = 0; j < 722; j++)
        n[i][j] = 0;

    for (int i = 0; i < r; i++) {
      int t, x, m, w;
      cin >> t >> x >> m >> w;
      t -= 540;
      if (w == 1)
        n[m][t] += 1;
      else {
        n[m][t] -= 1;
      }
    }
    for (int i = 0; i <= M; i++)
      for (int j = 0; j < 721; j++)
        n[i][j + 1] += n[i][j];

    int q, t1, t2, y;
    cin >> q;

    for (int i = 0; i < q; i++) {
      cin >> t1 >> t2 >> y;
      t1 -= 540;
      t2 -= 540;
      int c = 0;
      for (int j = t1; j < t2; j++) {
        if (n[y][j] != 0) {
          c++;
        } // cout<<j+540<<" "<<c<<n[y][j]<<endl;}
      }
      cout << c << endl;
    }
  }
  return 0;
}
Problem p00729 (C++) — buggy submission, verdict: Runtime Error

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

int dp[10001][722];

int main() {
  int N, M;
  while (cin >> N >> M, N || M) {
    memset(dp, 0, sizeof dp);
    int r;
    cin >> r;
    for (int i = 0; i < r; ++i) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      if (s == 1) {
        dp[m][t - 540] += 1;
      } else {
        dp[m][t - 540] -= 1;
      }
    }
    for (int i = 1; i <= M; ++i) {
      for (int j = 1; j < 722; ++j) {
        dp[i][j] = dp[i][j - 1] + dp[i][j];
      }
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
      int ts, te, m;
      cin >> ts >> te >> m;
      int cnt = 0;
      for (int j = ts; j < te; ++j) {
        cnt += (0 < dp[m][j - 540]);
      }
      cout << cnt << endl;
    }
  }
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  int N, M;
  while (cin >> N >> M, N || M) {
    int dp[10001][722] = {0};
    int r;
    cin >> r;
    for (int i = 0; i < r; ++i) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      if (s == 1) {
        dp[m][t - 540] += 1;
      } else {
        dp[m][t - 540] -= 1;
      }
    }
    for (int i = 1; i <= M; ++i) {
      for (int j = 1; j < 722; ++j) {
        dp[i][j] = dp[i][j - 1] + dp[i][j];
      }
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
      int ts, te, m;
      cin >> ts >> te >> m;
      int cnt = 0;
      for (int j = ts; j < te; ++j) {
        cnt += (0 < dp[m][j - 540]);
      }
      cout << cnt << endl;
    }
  }
  return 0;
}
Problem p00729 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int use[10004][1300];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  while (cin >> N >> M, N || M) {
    CLR(use);
    int r;
    cin >> r;
    FOR(i, 0, r) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      if (s == 1) {
        use[m][t]++;
      } else {
        use[m][t]--;
      }
    }
    FOR(i, 1, M + 1) {
      FOR(j, 0, 1299) { use[i][j + 1] += use[i][j]; }
    }
    int q;
    cin >> q;
    FOR(i, 0, q) {
      int ts, te, m;
      cin >> ts >> te >> m;
      int ans = 0;
      FOR(j, ts, te) {
        if (use[m][j] > 0)
          ans++;
      }
      cout << ans << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  while (cin >> N >> M, N || M) {
    int use[M + 1][1300];
    CLR(use);
    int r;
    cin >> r;
    FOR(i, 0, r) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      if (s == 1) {
        use[m][t]++;
      } else {
        use[m][t]--;
      }
    }
    FOR(i, 1, M + 1) {
      FOR(j, 0, 1299) { use[i][j + 1] += use[i][j]; }
    }
    int q;
    cin >> q;
    FOR(i, 0, q) {
      int ts, te, m;
      cin >> ts >> te >> m;
      int ans = 0;
      FOR(j, ts, te) {
        if (use[m][j] > 0)
          ans++;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
Problem p00729 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
const int MAXTIME = 1260;
void fill(vector<bool> &a, int s, int l) {
  for (int i = s; i < l; i++) {
    a[i] = true;
  }
  return;
}
int solve(vector<bool> &a, int s, int l) {
  int ans = 0;
  for (int i = s; i < l; i++) {
    if (a[i]) {
      ans++;
    }
    /*    if(a[i] == 1 && a[i+1] == 0){
      ans--;
      }*/
  }
  return ans;
}
int main() {
  while (1) {
    int N, M;
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;
    vector<vector<bool>> students(M, vector<bool>(MAXTIME + 2, false));
    // int students[10000][1260] = {0};
    vector<vector<int>> keep(M, vector<int>(N + 1, 0));

    int r;
    cin >> r;
    for (int i = 0; i < r; i++) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      if (s == 0) {
        fill(students[m - 1], keep[m - 1][n - 1], t);
      } else if (s == 1) {
        keep[m - 1][n - 1] = t;
      }
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
      int ts, te, m;
      cin >> ts >> te >> m;
      cout << solve(students[m - 1], ts, te) << endl;
    }
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
const int MAXTIME = 1260;
void fill(vector<int> &a, int s, int l) {
  for (int i = s; i < l; i++) {
    a[i] = 1;
  }
  return;
}
int solve(vector<int> &a, int s, int l) {
  int ans = 0;
  for (int i = s; i < l; i++) {
    if (a[i] == 1) {
      ans++;
    }
    /*    if(a[i] == 1 && a[i+1] == 0){
      ans--;
      }*/
  }
  return ans;
}
int main() {
  while (1) {
    int N, M;
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;
    vector<vector<int>> students(M, vector<int>(MAXTIME + 2, 0));
    vector<vector<int>> keep(M, vector<int>(N + 1, 0));

    int r;
    cin >> r;
    for (int i = 0; i < r; i++) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      if (s == 0) {
        fill(students[m - 1], keep[m - 1][n - 1], t);
      } else if (s == 1) {
        keep[m - 1][n - 1] = t;
      }
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
      int ts, te, m;
      cin >> ts >> te >> m;
      cout << solve(students[m - 1], ts, te) << endl;
    }
  }

  return 0;
}