Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int N, M, r, q;

int t, n, m, s, ts, te;

int time[1010][10010];
bool used[1000][10010];

int main(){
	while (cin >> N >> M&&N + M){
		cin >> r;
		REP(i, r){
			cin >> t >> n >> m >> s;
			t -= 540;
			if (s == 1){
				time[n][m] = t;
			}
			else{
				FOR(j, time[n][m], t){
					used[j][m] = 1;
				}
			}
		}
		cin >> q;
		REP(i, q){
			int ans = 0, t = -1;
			cin >> ts >> te >> m;
			ts -= 540;
			te -= 540;
			FOR(j, ts, te + 1){
				if (t == -1){
					if (used[j][m])t = j;
				}
				else{
					if (!used[j][m]){
						//cout << "!" << endl;
						//cout << j - 1 << " " << t << endl;
						ans += j - t;
						t = -1;
					}
				}
			}
			if (t != -1){
				ans += te - t;
			}
			cout << ans << endl;
		}
	}
}

Compiler output:
a.cc:44:21: error: 'int time [1010][10010]' redeclared as different kind of entity
   44 | int time[1010][10010];
      |                     ^
In file included from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr.h:157,
                 from /usr/include/c++/14/ext/atomicity.h:35,
                 from /usr/include/c++/14/bits/ios_base.h:39,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/time.h:76:15: note: previous declaration 'time_t time(time_t*)'
   76 | extern time_t time (time_t *__timer) __THROW;
      |               ^~~~
a.cc: In function 'int main()':
a.cc:54:39: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   54 |                                 time[n][m] = t;
      |                                       ^
a.cc:54:42: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   54 |                                 time[n][m] = t;
      |                                          ^
a.cc:54:44: error: assignment of read-only location '*(time + (((sizetype)n) + ((sizetype)m)))'
   54 |                                 time[n][m] = t;
      |                                 ~~~~~~~~~~~^~~
a.cc:57:46: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   57 |                                 FOR(j, time[n][m], t){
      |                                              ^
a.cc:20:37: note: in definition of macro 'FOR'
   20 | #define FOR(i,a,b) for(long long i=(a);i<(b);i++)
      |                                     ^
a.cc:57:49: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   57 |                                 FOR(j, time[n][m], t){
      |                                                 ^
a.cc:20:37: note: in definition of macro 'FOR'
   20 | #define FOR(i,a,b) for(long long i=(a);i<(b);i++)
      |                                     ^
a.cc:57:49: error: invalid conversion from 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} to 'long long int' [-fpermissive]
   57 |                                 FOR(j, time[n][m], t){
      |                                                 ^
      |                                                 |
      |                                                 time_t (*)(time_t*) noexcept {aka long int (*)(long int*) noexcept}
a.cc:20:37: note: in definition of macro 'FOR'
   20 | #define FOR(i,a,b) for(long long i=(a);i<(b);i++)
      |                                     ^