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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define INF 100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i, n) for (int i = 0; i < n; i++)
#define SORT(x) sort((x).begin(), (x).end())
#define clr(a, b) memset((a), (b), sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P>> PQ;

int deta[10000][1000];

int main() {
  int n, m;
  while (scanf("%d%d", &n, &m), n || m) {
    rep(i, 10000) rep(j, 1000) deta[i][j] = 0;
    int r;
    scanf("%d", &r);
    rep(i, r) {
      int a, b, c, d;
      scanf("%d%d%d%d", &a, &b, &c, &d);
      a -= 540;
      c--;
      if (d == 1) {
        deta[c][a]++;
      } else {
        deta[c][a]--;
      }
    }
    rep(i, 10000) {
      for (int j = 1; j < 1000; j++) {
        deta[i][j] += deta[i][j - 1];
      }
    }
    int q;
    scanf("%d", &q);
    rep(i, q) {
      int a, b, c;
      int cnt = 0;
      scanf("%d%d%d", &a, &b, &c);
      a -= 540;
      b -= 540;
      c--;
      for (int j = a; j < b; j++) {
        if (deta[c][j])
          cnt++;
      }
      printf("%d\\n", cnt);
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define INF 100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i, n) for (int i = 0; i < n; i++)
#define SORT(x) sort((x).begin(), (x).end())
#define clr(a, b) memset((a), (b), sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P>> PQ;

int deta[1000][1000];

int main() {
  int n, m;
  while (scanf("%d%d", &n, &m), n || m) {
    rep(i, 1000) rep(j, 1000) deta[i][j] = 0;
    int r;
    scanf("%d", &r);
    rep(i, r) {
      int a, b, c, d;
      scanf("%d%d%d%d", &a, &b, &c, &d);
      a -= 540;
      c--;
      if (d == 1) {
        deta[c][a]++;
      } else {
        deta[c][a]--;
      }
    }
    rep(i, 1000) {
      for (int j = 1; j < 1000; j++) {
        deta[i][j] += deta[i][j - 1];
      }
    }
    int q;
    scanf("%d", &q);
    rep(i, q) {
      int a, b, c;
      int cnt = 0;
      scanf("%d%d%d", &a, &b, &c);
      a -= 540;
      b -= 540;
      c--;
      for (int j = a; j < b; j++) {
        if (deta[c][j])
          cnt++;
      }
      printf("%d\\n", cnt);
    }
  }
}