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

#include <iostream>
using namespace std;

int main() {
  int n, m, r, q;
  static int cnt[10000][1261];
  while (cin >> n >> m, n) {
    for (int i = 0; i < m; i++) {
      for (int j = 0; j <= 1260; j++)
        cnt[i][j] = 0;
    }
    cin >> r;
    for (int i = 0; i < r; i++) {
      int t, a, b, s;
      cin >> t >> a >> b >> s;
      b--;
      if (s)
        cnt[b][t]++;
      else
        cnt[b][t]--;
    }
    for (int i = 0; i < m; i++) {
      for (int j = 1; j <= 1260; j++) {
        cnt[i][j] += cnt[i][j - 1];
        // if(j >= 774 && j <= 881) cout << cnt[i][j] << " ";
      }
      // cout << endl;
    }
    for (int i = 0; i < m; i++) {
      for (int j = 1; j <= 1260; j++) {
        if (cnt[i][j])
          cnt[i][j] = 1;
      }
    }
    for (int i = 0; i < m; i++) {
      for (int j = 1; j <= 1260; j++) {
        cnt[i][j] += cnt[i][j - 1];
      }
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
      int s, t, b;
      cin >> s >> t >> b;
      b--;
      cout << cnt[b][t - 1] - cnt[b][s - 1] << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, m, r, q;
  static int cnt[1000][1261];
  while (cin >> n >> m, n) {
    for (int i = 0; i < m; i++) {
      for (int j = 0; j <= 1260; j++)
        cnt[i][j] = 0;
    }
    cin >> r;
    for (int i = 0; i < r; i++) {
      int t, a, b, s;
      cin >> t >> a >> b >> s;
      b--;
      if (s)
        cnt[b][t]++;
      else
        cnt[b][t]--;
    }
    for (int i = 0; i < m; i++) {
      for (int j = 1; j <= 1260; j++) {
        cnt[i][j] += cnt[i][j - 1];
        // if(j >= 774 && j <= 881) cout << cnt[i][j] << " ";
      }
      // cout << endl;
    }
    for (int i = 0; i < m; i++) {
      for (int j = 1; j <= 1260; j++) {
        if (cnt[i][j])
          cnt[i][j] = 1;
      }
    }
    for (int i = 0; i < m; i++) {
      for (int j = 1; j <= 1260; j++) {
        cnt[i][j] += cnt[i][j - 1];
      }
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
      int s, t, b;
      cin >> s >> t >> b;
      b--;
      cout << cnt[b][t - 1] - cnt[b][s - 1] << endl;
    }
  }
  return 0;
}
Problem p00729 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

using namespace std;

typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<pair<int, int>> VII;

int main() {

  const int TS = 530, TE = 1270;
  const int SPAN = TE - TS;
  int N, M;
  while (cin >> N >> M, N) {
    int r;
    cin >> r;
    VVI dat(M, VI(SPAN, 0));
    for (int i = 0; i < r; i++) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      m--;
      t -= TS;
      if (s)
        dat[m][t]++;
      else
        dat[m][t]--;
    }

    for (int i = 0; i < M; i++) {
      // imos PCs login: 1 logout: -1
      for (int j = 0; j < SPAN; j++) {
        dat[i][j + 1] += dat[i][j];
      }
    }

    VVI dat2(M, VI(SPAN, 0));

    for (int i = 0; i < M; i++) {
      // 複数のPCをひとまとめにして、更に時間の累積和を取る
      for (int j = 0; j < SPAN; j++) {
        dat2[i][j + 1] = dat2[i][j] + (dat[i][j] > 0);
      }
    }

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
      int ts, te, m;
      cin >> ts >> te >> m;
      m--;
      ts -= TS;
      te -= TS;
      cout << dat2[m][te] - dat2[m][ts] << endl;
    }
  }

  return 0;
}

Error: MLE

Fixed submission:

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

using namespace std;

typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<pair<int, int>> VII;

int main() {

  int N, M;
  while (cin >> N >> M, N) {
    int r;
    cin >> r;
    VVI dat(M, VI(2014, 0));
    for (int i = 0; i < r; i++) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      m--;
      if (s)
        dat[m][t]++;
      else
        dat[m][t]--;
    }

    for (int i = 0; i < M; i++) {
      // imos PCs login: 1 logout: -1
      for (int j = 0; j < 2013; j++) {
        dat[i][j + 1] += dat[i][j];
      }
    }

    VVI dat2(M, VI(2014, 0));

    for (int i = 0; i < M; i++) {
      // 複数のPCをひとまとめにして、更に時間の累積和を取る
      for (int j = 0; j < 2013; j++) {
        dat2[i][j + 1] = dat2[i][j] + (dat[i][j] > 0);
      }
    }

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
      int ts, te, m;
      cin >> ts >> te >> m;
      m--;
      cout << dat2[m][te] - dat2[m][ts] << endl;
    }
  }

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

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

int students[10001][750] = {};
int numlogin[10001] = {};
int sum[10001][800] = {};

int main() {

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

    memset(students, 0, sizeof(students));
    memset(numlogin, 0, sizeof(numlogin));
    memset(sum, 0, sizeof(sum));

    // ?¨????
    for (int i = 0; i < r; i++) { // 1000
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      t -= 540;
      if (s == 0) { // ?????°??¢??????
        numlogin[m]--;
        if (numlogin[m] == 0) {
          for (int i = t - 1; students[m][i] != 1 and t >= 0; i--) { // 1000
            students[m][i] = 1;
          }
        }
      } else { // ?????°??????
        numlogin[m]++;
        if (numlogin[m] == 1)
          students[m][t] = 1;
      }
    }

    // ?´???????
    for (int i = 1; i <= M; i++) {     // 100000
      for (int j = 1; j <= 720; j++) { // 1000
        sum[i][j] = sum[i][j - 1] + students[i][j];
      }
    }

    // ??????
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
      int ts, te, id;
      cin >> ts >> te >> id;
      ts -= 540;
      te -= 540;
      cout << sum[id][te - 1] - sum[id][ts] + students[id][ts] << endl;
    }
  }
}

Error: MLE

Fixed submission:

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

int students[10001][800] = {};
int numlogin[10001] = {};
int sum[10001][800] = {};

int main() {

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

    memset(students, 0, sizeof(students));
    memset(numlogin, 0, sizeof(numlogin));
    memset(sum, 0, sizeof(sum));

    // ?¨????
    for (int i = 0; i < r; i++) { // 1000
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      t -= 540;
      if (s == 0) { // ?????°??¢??????
        numlogin[m]--;
        if (numlogin[m] == 0) {
          for (int i = t - 1; students[m][i] != 1 and t >= 0; i--) { // 1000
            students[m][i] = 1;
          }
        }
      } else { // ?????°??????
        numlogin[m]++;
        if (numlogin[m] == 1)
          students[m][t] = 1;
      }
    }

    // ?´???????
    for (int i = 1; i <= M; i++) {     // 100000
      for (int j = 1; j <= 720; j++) { // 1000
        sum[i][j] = sum[i][j - 1] + students[i][j];
      }
    }

    // ??????
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
      int ts, te, id;
      cin >> ts >> te >> id;
      ts -= 540;
      te -= 540;
      cout << sum[id][te - 1] - sum[id][ts] + students[id][ts] << endl;
    }
  }
}
Problem p00729 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int students[10001][800] = {};
int numlogin[10001] = {};
int sum[10001][800] = {};

int main() {

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

    cin >> r;

    memset(students, 0, sizeof(students));
    memset(numlogin, 0, sizeof(numlogin));
    memset(sum, 0, sizeof(sum));

    // ?¨????
    for (int i = 0; i < r; i++) { // 1000
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      t -= 540;
      if (s == 0) { // ?????°??¢??????
        numlogin[m]--;
        if (numlogin[m] == 0) {
          for (int i = t - 1; students[m][i] != 1 and t >= 0; i--) { // 1000
            students[m][i] = 1;
          }
        }
      } else { // ?????°??????
        numlogin[m]++;
        if (numlogin[m] == 1)
          students[m][t] = 1;
      }
    }

    // ?´???????

    for (int i = 1; i <= M; i++) {     // 100000
      for (int j = 1; j <= 720; j++) { // 1000
        sum[i][j] = sum[i][j - 1] + students[i][j];
        //	students[i][j] += students[i][j-1];
      }
    }

    // ??????
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
      int ts, te, id;
      cin >> ts >> te >> id;
      ts -= 540;
      te -= 540;
      cout << sum[id][te - 1] - sum[id][ts] + students[id][ts] << endl;
      //      cout << students[id][te] - students[id][ts] << endl;
      // cout << students[id][te] - students[id][ts] << endl;
    }
  }
}

Error: MLE

Fixed submission:

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

int students[10001][800] = {};
int numlogin[10001] = {};
int sum[10001][800] = {};
int main() {

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

    cin >> r;
    // 4byte * 10^7

    memset(students, 0, sizeof(students));
    memset(numlogin, 0, sizeof(numlogin));
    memset(sum, 0, sizeof(sum));

    // ?¨????
    for (int i = 0; i < r; i++) { // 1000
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      t -= 560;
      if (s == 0) { // ?????°??¢??????
        numlogin[m]--;
        if (numlogin[m] == 0) {
          for (int i = t - 1; students[m][i] != 1 and t >= 0; i--) { // 1000
            students[m][i] = 1;
          }
        }
      } else { // ?????°??????
        numlogin[m]++;
        if (numlogin[m] == 1)
          students[m][t] = 1;
      }
    }

    // ?´???????

    for (int i = 1; i <= M; i++) {    // 100000
      for (int j = 1; j < 790; j++) { // 1000
        sum[i][j] = sum[i][j - 1] + students[i][j];
        //	students[i][j] += students[i][j-1];
      }
    }

    // ??????
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
      int ts, te, id;
      cin >> ts >> te >> id;
      ts -= 560;
      te -= 560;
      cout << sum[id][te - 1] - sum[id][ts] + students[id][ts] << endl;
      //      cout << students[id][te] - students[id][ts] << endl;
      // cout << students[id][te] - students[id][ts] << endl;
    }
  }
}
Problem p00729 (C++) — buggy submission, verdict: Runtime Error

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

#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX / 3

#define MAX_N 1000

int use[11111][1300];
int N, M, r, q;

int main() {
  cin.sync_with_stdio(false);
  while (1) {
    cin >> N >> M;
    if (N == 0)
      break;
    memset(use, 0, sizeof(use));
    cin >> r;
    rep(i, r) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      n--;
      m--;
      if (s == 1) {
        use[m][t] += 1;
      } else {
        use[m][t] -= 1;
      }
    }
    rep(i, M) repl(j, 540, 1300) { use[i][j + 1] += use[i][j]; }
    cin >> q;
    rep(i, q) {
      int ts, te, m;
      cin >> ts >> te >> m;
      m--;
      int res = 0;
      repl(j, ts, te) {
        if (use[m][j] > 0)
          res++;
      }
      cout << res << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX / 3

#define MAX_N 1000

int use[1111][1300];
int N, M, r, q;

int main() {
  cin.sync_with_stdio(false);
  while (1) {
    cin >> N >> M;
    if (N == 0)
      break;
    memset(use, 0, sizeof(use));
    cin >> r;
    rep(i, r) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      n--;
      m--;
      if (s == 1) {
        use[m][t] += 1;
      } else {
        use[m][t] -= 1;
      }
    }
    rep(i, M) repl(j, 540, 1300) { use[i][j + 1] += use[i][j]; }
    cin >> q;
    rep(i, q) {
      int ts, te, m;
      cin >> ts >> te >> m;
      m--;
      int res = 0;
      repl(j, ts, te) {
        if (use[m][j] > 0)
          res++;
      }
      cout << res << endl;
    }
  }
  return 0;
}
Problem p00729 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define all(n) n.begin(), n.end()

const int MAXN = 1000, MAXM = 10000, MAXR = 1000, MAXQ = 50, MAXT = 1260;

int mem[MAXM + 1][MAXT + 1];

const int LOGIN = 1, LOGOUT = 0;
int main() {
  int n, m;
  while (cin >> n >> m && n) {
    memset(mem, 0, sizeof(mem));
    int r;
    cin >> r;
    int rt, rn, rm, rs;
    REP(r) {
      cin >> rt >> rn >> rm >> rs;
      if (rs == LOGIN)
        for (int j = rt; j <= MAXT; j++)
          mem[rm][j] += 1;
      else
        for (int j = rt; j <= MAXT; j++)
          mem[rm][j] -= 1;
    }
    int q;
    cin >> q;
    REP(q) {
      int ts, te, qm;
      cin >> ts >> te >> qm;
      int ans = 0;

      for (int j = ts; j < te; j++)
        if (mem[qm][j] > 0)
          ans++;

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define all(n) n.begin(), n.end()

typedef pair<int, int> p;
const int W = 0, H = 1;

int main() {
  int n, w, d;
  while (cin >> n >> w >> d && w) {
    vector<p> cakes;
    cakes.push_back(p(w, d));
    REP(n) {
      int pn, s;
      cin >> pn >> s;
      pn--;
      int side[2];
      side[W] = cakes[pn].first;
      side[H] = cakes[pn].second;
      vector<p>::iterator it = cakes.begin();
      rep(j, pn)++ it;

      cakes.erase(it);
      int sn = W;
      while (side[sn] < s) {
        s -= side[sn];
        sn = (sn + 1) % 2;
      }
      int neww[2];
      neww[0] = min(s, side[sn] - s);
      neww[1] = max(s, side[sn] - s);
      if (sn == W) {
        cakes.push_back(p(neww[0], side[H]));
        cakes.push_back(p(neww[1], side[H]));
      } else {
        cakes.push_back(p(side[W], neww[0]));
        cakes.push_back(p(side[W], neww[1]));
      }
    }
    vector<int> ans;
    REP(n + 1) ans.push_back(cakes[i].first * cakes[i].second);
    sort(all(ans));
    REP(n) cout << ans[i] << " ";
    cout << ans[n] << endl;
  }
  return 0;
}
Problem p00729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int r, q, a, b, c;
  while (cin >> r, r) {
    cin >> r >> r;
    vector<int> t(r), m(r), s(r);
    for (int i = 0; i < r; ++i) {
      cin >> t[i] >> m[i] >> m[i] >> s[i];
    }
    cin >> q;
    for (int i = 0; i < q; ++i) {
      cin >> a >> b >> c;
      int ans = 0, cnt = 0, p = a;
      for (int i = 0; i < t.size(); ++i) {
        int u = min(t[i], b);
        if (cnt)
          ans += max(u - p, 0);
        if (m[i] == c) {
          if (s[i])
            cnt++;
          else
            cnt--;
        }
        p = max(p, u);
      }
      printf("%d\\n", ans);
    }
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define r(i, a, n) for (int i = a; i < n; i++)
using namespace std;
int main() {
  int n, p, a[100][1261 - 539], ch[100][1261 - 539];
  while (cin >> n >> p, n) {
    int q, b, c, d, e;
    r(i, 0, p) r(j, 0, 1261 - 539) ch[i][j] = a[i][j] = 0;
    cin >> q;
    r(i, 0, q) {
      cin >> b >> c >> d >> e;
      b -= 539;
      if (e == 1) {
        a[d - 1][b]++;
        ch[d - 1][b] = c;
      } else {
        for (int j = b - 1; j >= 0; j--) {
          if (ch[d - 1][j] == c)
            break;
          a[d - 1][j]++;
        }
      }
    }
    cin >> q;
    while (q--) {
      int s = 0;
      cin >> b >> c >> d;
      b -= 539;
      c -= 539;
      r(i, b, c) if (a[d - 1][i]) s++;
      cout << s << endl;
    }
  }
}
Problem p00729 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
// #include <bits/stdc++.h>

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long
#define bl bool
#define nn printf("\\n");
#define mod 1000000007

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  while (cin >> N >> M && N != 0 && M != 0) {
    int r;
    cin >> r;
    vector<vector<int>> dat(M + 2, vector<int>(722, 0));
    vector<vector<int>> ttmp(M + 2, vector<int>(N + 2, 0));
    rep(i, r) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      if (s == 1) {
        ttmp[m][n] = t - 540;
      } else if (s == 0) {
        fill(dat[m].begin() + ttmp[m][n], dat[m].begin() + (t - 540), 1);
      }
    }
    int q;
    cin >> q;
    rep(i, q) {
      int ts, te, m;
      cin >> ts >> te >> m;
      printf("%d\\n", accumulate(dat[m].begin() + (ts - 540),
                                dat[m].begin() + (te - 540), 0));
    }
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
// #include <bits/stdc++.h>

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long
#define bl bool
#define nn printf("\\n");
#define mod 1000000007

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  while (cin >> N >> M && N != 0 && M != 0) {
    int r;
    cin >> r;
    vector<vector<vector<int>>> dat(
        M + 2, vector<vector<int>>(N + 2, vector<int>(722, 0)));
    vector<vector<int>> ttmp(M + 2, vector<int>(N + 2, 0));
    rep(i, r) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      if (s == 1) {
        ttmp[m][n] = t - 540;
      } else if (s == 0) {
        fill(dat[m][n].begin() + ttmp[m][n], dat[m][n].begin() + (t - 540), 1);
      }
    }
    int q;
    cin >> q;
    rep(i, q) {
      int ts, te, m;
      cin >> ts >> te >> m;
      int ans = 0;
      for (int j = ts - 540; j < te - 540; j++) {
        int tmp = 0;
        rep(k, N + 1) {
          if (dat[m][k][j] == 1) {
            tmp++;
          }
        }
        if (tmp > 0) {
          ans++;
        }
      }
      printf("%d\\n", ans);
    }
  }
  return 0;
}
Problem p00729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int a[10010][1310];

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

  int n, m;
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    rep(i, 10010) rep(j, 1310) a[i][j] = 0;
    int r;
    cin >> r;
    rep(i, r) {
      int T, N, M, S;
      cin >> T >> N >> M >> S;
      int x = (S == 1 ? 1 : -1);
      T++;
      a[M - 1][T] += x;
    }
    rep(i, m) rep(j, 1300) a[i][j + 1] += a[i][j];
    rep(i, m) rep(j, 1300) if (a[i][j] > 1) a[i][j] = 1;
    rep(i, m) rep(j, 1300) a[i][j + 1] += a[i][j];
    int q;
    cin >> q;
    while (q--) {
      int A, B, C;
      cin >> A >> B >> C;
      C--;
      cout << a[C][B] - a[C][A] << endl;
    }
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int a[1010][1310];

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

  int n, m;
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    rep(i, 1010) rep(j, 1310) a[i][j] = 0;
    int r;
    cin >> r;
    rep(i, r) {
      int T, N, M, S;
      cin >> T >> N >> M >> S;
      int x = (S == 1 ? 1 : -1);
      T++;
      a[M - 1][T] += x;
    }
    rep(i, m) rep(j, 1300) a[i][j + 1] += a[i][j];
    rep(i, m) rep(j, 1300) if (a[i][j] > 1) a[i][j] = 1;
    rep(i, m) rep(j, 1300) a[i][j + 1] += a[i][j];
    int q;
    cin >> q;
    while (q--) {
      int A, B, C;
      cin >> A >> B >> C;
      C--;
      cout << a[C][B] - a[C][A] << endl;
    }
  }
}