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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

void remove_minmax(vector<int> &data) {
  int max = 0;
  int min = 1000000;
  int min_i = 0;
  int max_i = 0;
  int count = 0;
  vector<int>::iterator it = data.begin();
  while (it != data.end()) {
    if (*it < min) {
      min = *it;
      min_i = count;
    }
    if (*it > max) {
      max = *it;
      max_i = count;
    }
    ++count;
    ++it;
  }
  data[max_i] = 0;
  data[min_i] = 0;
}

int main(void) {
  int n;
  while (cin >> n) {
    if (n == 0) {
      return 0;
    }

    vector<int> data;

    for (int i = 0; i < n; ++i) {
      int num;
      cin >> num;
      data.push_back(num);
    }
    remove_minmax(data);

    int total =
        floor((double)accumulate(data.begin(), data.end(), 0) / (n - 2));
    cout << total << endl;
  }
  return 0;
}

Error: 255

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

void remove_minmax(vector<int> &data) {
  int max = 0;
  int min = 1000000;
  int min_i = 0;
  int max_i = 0;
  int count = 0;
  vector<int>::iterator it = data.begin();
  while (it != data.end()) {
    if (*it < min) {
      min = *it;
      min_i = count;
    }
    if (*it > max) {
      max = *it;
      max_i = count;
    }
    ++count;
    ++it;
  }
  data[max_i] = 0;
  data[min_i] = 0;
}

int main(void) {
  int n;
  while (cin >> n) {
    if (n == 0) {
      return -1;
    }

    vector<int> data;

    for (int i = 0; i < n; ++i) {
      int num;
      cin >> num;
      data.push_back(num);
    }
    remove_minmax(data);

    int total =
        floor((double)accumulate(data.begin(), data.end(), 0) / (n - 2));
    cout << total << endl;
  }
  return 0;
}
Problem p00728 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

const int calc(int *, int);

int main() {

  int data[100] = {};
  int count = 0;
  while (true) {
    cin >> count;
    if (count == 0)
      break;
    for (int i = 0; i < count; i++) {
      cin >> data[i];
    }

    for (int i = 1; i < count; i++) {
      for (int j = i; j > 0; j--) {
        if (data[j - 1] > data[j]) {
          int tmp = data[j];
          data[j] = data[j - 1];
          data[j - 1] = tmp;
        }
      }
    }
    cout << calc(data, count) << endl;
  }

  return 0;
}

const int calc(int *a, int count) {
  if (count <= 0)
    return 0;

  int ave = 0;

  for (int i = 1; i < count - 1; i++)
    ave += a[i];
  return ave / (count - 2);
}

Error: TLE

Fixed submission:

#include <iostream>
// #include<fstream>

using namespace std;

const int calc(int *, int);

int main() {
  // ifstream fin("in.txt");

  int data[20] = {};
  int count = 0;
  while (true) {
    cin >> count;
    if (count == 0)
      break;
    for (int i = 0; i < count; i++) {
      cin >> data[i];
    }

    for (int i = 1; i < count; i++) {
      for (int j = i; j > 0; j--) {
        if (data[j - 1] > data[j]) {
          int tmp = data[j];
          data[j] = data[j - 1];
          data[j - 1] = tmp;
        }
      }
    }
    cout << calc(data, count) << endl;
  }

  return 0;
}

const int calc(int *a, int count) {
  if (count <= 0)
    return 0;

  int ave = 0;

  for (int i = 1; i < count - 1; i++)
    ave += a[i];
  return ave / (count - 2);
}
Problem p00728 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#define rep(i, a) for (int i = 0; i < (a); ++i)

int n;

int main() {
  while (std::cin >> n, n) {
    int ma = 0, mi = 1001, S = 0;

    rep(i, n) {
      int a;
      std::cin >> a;
      ma = std::max(ma, a);
      mi = std::min(mi, a);
      S += a;
    }

    std::cout << (S - ma - mi) / (n - 2) << std::endl;
  }

  return 0;
}

Error: -8

Fixed submission:

#include <algorithm>
#include <iostream>
#define rep(i, a) for (int i = 0; i < (a); ++i)

int n;

int main() {
  while (std::cin >> n) {
    int ma = 0, mi = 1001, S = 0;

    rep(i, n) {
      int a;
      std::cin >> a;
      ma = std::max(ma, a);
      mi = std::min(mi, a);
      S += a;
    }

    std::cout << (S - ma - mi) / n << std::endl;
  }

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

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

int main() {
  int n, data;
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    int sum = 0, max = 0, min = 1001;
    for (int i = 0; i < n; i++) {
      scanf("%d", &data);
      sum += data;
      if (max < data)
        max = data;
      if (data < min)
        min = data;
    }
    printf("%d\\n", (sum - max - min) / (n - 2));
  }
}

Error: WA

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int N, input;
  while (1) {
    scanf("%d", &N);
    if (N == 0) {
      break;
    }
    int sum = 0, max = 0, min = 1001;
    for (int i; i < N; i++) {
      cin >> input;
      sum = sum + input;
      if (max < input)
        max = input;
      if (min > input)
        min = input;
    }
    printf("%d\\n", (sum - max - min) / (N - 2));
  }
}
Problem p00728 (C++) — buggy submission, verdict: Runtime Error

#include <climits>
#include <iostream>
#include <vector>

int main(void) {
  while (1) {
    int n;
    std::vector<signed int> s;
    std::vector<signed int>::iterator it;

    std::cin >> n;
    if (n == 0)
      return 0;
    for (int i = 0; i < n; i++) {
      int inputting;
      std::cin >> inputting;
      s.push_back(inputting);
    }

    int max = -1, min = INT_MAX;
    std::vector<signed int>::iterator maxind;
    std::vector<signed int>::iterator minind;
    for (it = s.begin(); it != s.end(); ++it) {
      if (*it > max) {
        max = *it;
        maxind = it;
      }
    }
    s.erase(maxind);

    for (it = s.begin(); it != s.end(); ++it) {
      if (*it < min) {
        min = *it;
        minind = it;
      }
    }
    s.erase(minind);

    int sum = 0, avr;
    for (it = s.begin(); it != s.end(); it++) {
      sum += *it;
    }
    std::cout << sum / s.size() << std::endl;
  }
}

Error: WA

Fixed submission:

#include <climits>
#include <iostream>
#include <vector>

int main(void) {
  while (1) {
    int n;
    std::vector<signed int> s;
    std::vector<signed int>::iterator it;

    std::cin >> n;
    if (n == 0)
      return 0;
    for (int i = 0; i < n; i++) {
      int inputting;
      std::cin >> inputting;
      s.push_back(inputting);
    }

    int max = -1, min = 1001;
    std::vector<int>::iterator maxind, minind;
    for (it = s.begin(); it != s.end(); it++) {
      if (*it > max) {
        max = *it;
        maxind = it;
      }
      if (*it < min) {
        if (*it == 0)
          min = 0;
        else {
          min = *it;
          minind = it;
        }
      }
    }

    s.erase(maxind);
    s.erase(minind);
    int sum = 0, avr;
    for (it = s.begin(); it != s.end(); it++) {
      sum += *it;
    }
    std::cout << sum / s.size() << std::endl;
  }
}
Problem p00728 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n, max, min, s;
  long sum;

  while (true) {
    cin >> n;
    sum = max = 0;
    min = 1000;

    if (n == 0)
      break;

    for (int i = 0; i < n; i++) {
      cin >> s;
      if (s < min)
        min = s;
      if (s > max)
        max = s;
      sum += s;
    }
    sum -= (min + max);
    cout << sum / (n - 2) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int add(int, int);

int main() {
  int x, y, s, max, a;

  while (true) {
    int max = 0;
    cin >> x >> y >> s;

    if (x == 0 && y == 0 && s == 0)
      break;

    for (int i = 1; i < s; i++) {
      for (int j = 1; j < s; j++) {
        if ((add(i, x) + add(j, x)) == s) {
          a = (add(i, y) + add(j, y));
          if (a > max)
            max = a;
        }
      }
    }
    cout << max << endl;
  }

  return 0;
}

int add(int a, int t) { return a * (100 + t) / 100; }
Problem p00728 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  while (1) {
    int judge;
    int maxscore = 0;
    int minscore = 0;
    cin >> judge;
    if (judge != 0) {
      int score[judge];
      for (int i = 0; i < judge; i++) {
        cin >> score[i];
        if (score[i] > maxscore) {
          maxscore = score[i];
        }
        if (score[i] < minscore) {
          minscore = score[i];
        }
        if (i == 0) {
          minscore = score[0];
        }
      }
      int lastscore = 0;
      for (int j = 0; j < judge; j++) {
        lastscore += score[j];
      }
      lastscore = (lastscore - maxscore - minscore) / (judge - 2);
      cout << lastscore << endl;
    } else
      break;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  while (1) {
    int judge;
    int maxscore = 0;
    int minscore = 0;
    cin >> judge;
    if (judge != 0) {
      int score[judge];
      for (int i = 0; i < judge; i++) {
        cin >> score[i];
        if (score[i] > maxscore) {
          maxscore = score[i];
        }
        if (score[i] < minscore) {
          minscore = score[i];
        }
        if (i == 0) {
          minscore = score[0];
        }
      }
      int lastscore = 0;
      for (int j = 0; j < judge; j++) {
        lastscore += score[j];
      }
      lastscore = (lastscore - maxscore - minscore) / (judge - 2);
      cout << lastscore << endl;
    }
  }
  return 0;
}
Problem p00729 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#include <stack>
#include <vector>
using namespace std;
int main() {
  int N, M;
  while (cin >> N >> M) {
    if (N == 0 && M == 0)
      break;
    int r, q;
    vector<int> pc(N + 1, 0);
    vector<vector<int>> time(M + 1, vector<int>(1261, 0));
    cin >> r;
    for (int i = 0; i < r; i++) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      if (s == 1) {
        time[m][t] = 1;
        pc[n] = t;
      } else if (s == 0) {
        for (int j = pc[n]; j < t; j++) {
          time[m][j] = 1;
        }
        pc[n] = 0;
      }
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
      int ts, te, mn, count = 0;
      cin >> ts >> te >> mn;
      for (int j = ts; j < te; j++) {
        if (time[mn][j] == 1)
          count++;
      }
      cout << count << endl;
    }
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
#include <stack>
#include <vector>
using namespace std;
int main() {
  int N, M;
  while (cin >> N >> M) {
    if (N == 0 && M == 0)
      break;
    int r, q;
    vector<vector<int>> pc(N + 1, vector<int>(M + 1, 0));
    vector<vector<int>> time(M + 1, vector<int>(1261, 0));
    cin >> r;
    for (int i = 0; i < r; i++) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      if (s == 1) {
        time[m][t] = 1;
        pc[n][m] = t;
      } else if (s == 0) {
        for (int j = pc[n][m]; j < t; j++) {
          time[m][j] = 1;
        }
        pc[n][m] = 0;
      }
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
      int ts, te, mn, count = 0;
      cin >> ts >> te >> mn;
      for (int j = ts; j < te; j++) {
        if (time[mn][j] == 1)
          count++;
      }
      cout << count << endl;
    }
  }
  return 0;
}
Problem p00729 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define FOR(k, m, n) for (int(k) = (m); (k) < (n); (k)++)
#define REP(i, n) FOR((i), 0, (n))
#define LL long long
#define CLR(a) memset((a), 0, sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str)                                                           \\
  int str;                                                                     \\
  std::cin >> str;
#define DEBUGING(str) cout << str << endl
using namespace std;

const LL MOD = 1000000007; // 10^9+7
const int INF = (1 << 30);

// 変数
struct Database {
  int N, M, r, q;
  vector<vector<int>> use;

  Database() {
    cin >> N >> M;
    if (N == 0)
      return;
    use.resize(M + 1, vector<int>(60 * 24));

    cin >> r;
    REP(i, r) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      use[m][t] += (s == 1 ? 1 : -1);
    }
    REP(i, M + 1) REP(t, 60 * 24 - 1) use[i][t + 1] += use[i][t];
  }

  void query() {

    int ts, te, m;
    cin >> ts >> te >> m;

    int res = 0;
    FOR(t, ts, te) { res += (use[m][t] > 0 ? 1 : 0); }
    // cerr << "==========";
    cout << res << endl;
  }
};

// メイン関数
int main() {
  while (true) {
    Database base;
    if (base.N == 0)
      break;

    int q;
    cin >> q;
    REP(i, q) base.query();
  }

  return 0;
}


Error: 0
==========================================================================================

Fixed submission:

#include <algorithm>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define FOR(k, m, n) for (int(k) = (m); (k) < (n); (k)++)
#define REP(i, n) FOR((i), 0, (n))
#define LL long long
#define CLR(a) memset((a), 0, sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str)                                                           \\
  int str;                                                                     \\
  std::cin >> str;
#define DEBUGING(str) cout << str << endl
using namespace std;

const LL MOD = 1000000007; // 10^9+7
const int INF = (1 << 30);

// 変数
struct Database {
  int N, M, r, q;
  vector<vector<int>> use;

  Database() {
    cin >> N >> M;
    if (N == 0)
      return;
    use.resize(M + 1, vector<int>(60 * 24));

    cin >> r;
    REP(i, r) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      use[m][t] += (s == 1 ? 1 : -1);
    }
    REP(i, M + 1) REP(t, 60 * 24 - 1) use[i][t + 1] += use[i][t];
  }

  void query() {

    int ts, te, m;
    cin >> ts >> te >> m;

    int res = 0;
    FOR(t, ts, te) { res += (use[m][t] > 0 ? 1 : 0); }
    cerr << "==========";
    cout << res << endl;
  }
};

// メイン関数
int main() {
  while (true) {
    Database base;
    if (base.N == 0)
      break;

    int q;
    cin >> q;
    REP(i, q) base.query();
  }

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

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

typedef vector<int> V;

typedef struct {
  int t, n, m, s;
} Record;

int main() {
  int n, m, r, q;

  while (cin >> n >> m, n + m) {
    const int MAX = 1260 - 540;

    cin >> r;
    Record d[r];
    vector<V> v(m, V(MAX + 1, -1)), cnt(m, V(MAX + 1, 0));
    int use[1001] = {0};

    for (int i = 0; i < r; i++) {
      cin >> d[i].t >> d[i].n >> d[i].m >> d[i].s;
      if (d[i].s) {
        use[d[i].n - 1] = d[i].t;
      } else {
        for (int j = use[d[i].n - 1]; j < d[i].t; j++) {
          cnt[d[i].m - 1][j - 540] = 1;
        }
      }
    }

    int ts, tt, sn;
    cin >> q;
    for (int i = 0; i < q; i++) {
      cin >> ts >> tt >> sn;

      sn--;
      bool flg = true;
      int ans = 0;
      for (int i = ts; i < tt; i++) {
        if (cnt[sn][i - 540] != 0) {
          ans++;
        }
      }
      cout << ans << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

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

typedef vector<int> V;

typedef struct {
  int t, n, m, s;
} Record;

int main() {
  int n, m, r, q;

  while (cin >> n >> m, n + m) {
    const int MAX = 1260 - 540;

    cin >> r;
    Record d[r];
    int cnt[m + 1][MAX + 1];
    int use[m + 1][n + 1];

    memset(use, 0, sizeof(use));
    memset(cnt, 0, sizeof(cnt));

    for (int i = 0; i < r; i++) {
      cin >> d[i].t >> d[i].n >> d[i].m >> d[i].s;
      if (d[i].s) {
        use[d[i].m][d[i].n] = d[i].t;
      } else {
        for (int j = use[d[i].m][d[i].n]; j < d[i].t; j++) {
          cnt[d[i].m][j - 540] = 1;
        }
      }
    }

    int ts, tt, sn;
    cin >> q;
    for (int i = 0; i < q; i++) {
      cin >> ts >> tt >> sn;

      int ans = 0;
      for (int i = ts; i < tt; i++) {
        if (cnt[sn][i - 540])
          ans++;
      }
      cout << ans << endl;
    }
  }

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

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

int main() {
  while (1) { // start

    int N, M, r;
    // N；PC数　M；学生数
    cin >> N >> M;
    if (N == 0 and M == 0)
      break;
    cin >> r;

    // 学生数、　時間
    int data[10004][721];
    for (int j = 0; j < 10004; j++) {
      for (int k = 0; k < 721; k++)
        data[j][k] = 0;
    }

    for (int i = 0; i < r; i++) {
      // t；時刻、　n;PC番号　m；学生番号　s；１ならログイン、０ならログアウト(配列中では逆)
      int t, n, m;
      bool s;
      cin >> t >> n >> m >> s;
      if (s)
        data[m][t - 539] += 1;
      else
        data[m][t - 539] += -1;
    }

    // 累積和をとる
    for (int i = 0; i <= M; i++) {
      for (int k = 1; k < 721; k++)
        data[i][k] = data[i][k] + data[i][k - 1];
    }

    // クエリを取得
    int qn;
    cin >> qn;
    for (int i = 0; i < qn; i++) {
      int ts, tt, sn;
      cin >> ts >> tt >> sn;

      // 学生について調査する
      int ans = 0;
      for (int j = ts - 539; j < tt - 539; j++) {
        if (data[sn][j])
          ans++;
      }
      cout << ans << endl;
    }

  } // end

  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  while (1) { // start

    int N, M, r;
    // N；PC数　M；学生数
    cin >> N >> M;
    if (N == 0 and M == 0)
      break;
    cin >> r;

    // 学生数、　時間
    int data[1004][721];
    for (int j = 0; j < 1004; j++) {
      for (int k = 0; k < 721; k++)
        data[j][k] = 0;
    }

    for (int i = 0; i < r; i++) {
      // t；時刻、　n;PC番号　m；学生番号　s；１ならログイン、０ならログアウト(配列中では逆)
      int t, n, m;
      bool s;
      cin >> t >> n >> m >> s;
      if (s)
        data[m][t - 539] += 1;
      else
        data[m][t - 539] += -1;
    }

    // 累積和をとる
    for (int i = 0; i <= M; i++) {
      for (int k = 1; k < 721; k++)
        data[i][k] = data[i][k] + data[i][k - 1];
    }

    // クエリを取得
    int qn;
    cin >> qn;
    for (int i = 0; i < qn; i++) {
      int ts, tt, sn;
      cin >> ts >> tt >> sn;

      // 学生について調査する
      int ans = 0;
      for (int j = ts - 539; j < tt - 539; j++) {
        if (data[sn][j])
          ans++;
      }
      cout << ans << endl;
    }

  } // end

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

#include <cstring>
#include <iostream>
using namespace std;
int x[10000][1440], y[10000], n, m, r, q, i, j, a, b, c, d, s;
int main() {
  while (true) {
    memset(x, 0, sizeof(x));
    cin >> n >> m >> r;
    if (n == 0) {
      break;
    }
    for (i = 0; i < r; i++) {
      cin >> a >> b >> c >> d;
      if (d == 1) {
        y[c]++;
        for (j = a; j < 1440; j++) {
          x[c][j] = 1;
        }
      } else {
        y[c]--;
        if (y[c] == 0) {
          for (j = a; j < 1440; j++) {
            x[c][j] = 0;
          }
        }
      }
    }
    cin >> q;
    for (i = 0; i < q; i++) {
      s = 0;
      cin >> a >> b >> c;
      for (j = a; j < b; j++) {
        if (x[c][j] == 1) {
          s++;
        }
      }
      cout << s << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
int x[10000][1440], n, m, r, q, i, j, a, b, c, d, s;
int main() {
  while (true) {
    memset(x, 0, sizeof(x));
    cin >> n >> m >> r;
    for (i = 0; i < r; i++) {
      cin >> a >> b >> c >> d;
      if (d == 1) {
        for (j = a; j < 1440; j++) {
          x[c][j] = 1;
        }
      } else {
        for (j = a; j < 1440; j++) {
          x[c][j] = 0;
        }
      }
    }
    cin >> q;
    for (i = 0; i < q; i++) {
      s = 0;
      cin >> a >> b >> c;
      for (j = a; j < b; j++) {
        if (x[c][j] == 1) {
          s++;
        }
      }
      cout << s << endl;
    }
  }
}
Problem p00729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

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

  int N, M;
  while (true) {
    cin >> N >> M;
    if (N == 0)
      break;
    int r;
    cin >> r;
    VVI v(M, vector<int>(1000, 0));
    for (int i = 0; i < r; i++) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      t -= 540;
      m--;
      if (s)
        v[m][t]++;
      else
        v[m][t]--;
    }
    for (int i = 0; i < M; i++) {
      for (int j = 1; j <= 720; j++) {
        v[i][j] += v[i][j - 1];
      }
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
      int ts, te, m;
      cin >> ts >> te >> m;
      ts -= 540;
      te -= 540;
      m--;
      int res = 0;
      for (int j = ts; j < te; j++)
        if (v[m][j])
          res++;
      cout << res << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0)
      break;
    int r, q;
    int time[m + 1][721];
    for (int i = 0; i < m + 1; i++)
      for (int j = 0; j < 721; j++)
        time[i][j] = 0;
    cin >> r;
    for (int i = 0; i < r; i++) {
      int t, pc, stu, s;
      cin >> t >> pc >> stu >> s;
      t -= 540;
      if (s)
        time[stu][t]++;
      else
        time[stu][t]--;
    }
    for (int i = 1; i <= m; i++)
      for (int j = 1; j < 721; j++)
        time[i][j] += time[i][j - 1];
    cin >> q;
    for (int i = 0; i < q; i++) {
      int ts, te, stu;
      cin >> ts >> te >> stu;
      int res = 0;
      ts -= 540;
      te -= 540;
      for (int j = ts; j < te; j++)
        if (time[stu][j])
          res++;
      cout << res << endl;
    }
  }
}
Problem p00729 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>

#pragma warning(disable : 4996)

#define MAX_N 1000
#define MAX_M 10000

int N, M, R, Q, t1, n1, m1, s1, s, e, m;

int record[MAX_M + 1][1260];

int cpu_[MAX_N + 1];

int main() {
  while (true) {
    scanf("%d", &N);
    scanf("%d", &M);

    if (N == 0 && M == 0) {
      break;
    }

    scanf("%d", &R);

    for (int i = 0; i < R; i++) {
      scanf("%d", &t1);
      scanf("%d", &n1);
      scanf("%d", &m1);
      scanf("%d", &s1);

      if (cpu_[n1] == 0) {
        cpu_[n1] = t1;
      } else {
        for (int j = cpu_[n1]; j < t1; j++) {
          record[m1][j] = 1;
        }

        cpu_[n1] = 0;
      }
    }

    scanf("%d", &Q);

    for (int i = 0; i < Q; i++) {
      scanf("%d", &s);
      scanf("%d", &e);
      scanf("%d", &m);

      int count = 0;

      for (int j = s; j < e; j++) {
        count += record[m][j];
      }

      printf("%d\\n", count);
    }

    for (int i = 1; i <= M; i++) {
      for (int j = 540; j < 1260; j++) {
        record[i][j] = 0;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>

#pragma warning(disable : 4996)

#define MAX_M 10000

int N, M, R, Q, t1, n1, m1, s1, t2, m2, n2, s2, s, e, m;

int record[MAX_M + 1][1260];

int main() {
  while (true) {
    scanf("%d", &N);
    scanf("%d", &M);
    scanf("%d", &R);

    for (int i = 0; i < (R / 2); i++) {
      scanf("%d", &t1);
      scanf("%d", &n1);
      scanf("%d", &m1);
      scanf("%d", &s1);
      scanf("%d", &t2);
      scanf("%d", &n2);
      scanf("%d", &m2);
      scanf("%d", &s2);

      for (int j = t1; j < t2; j++) {
        record[m1][j] = 1;
      }
    }

    scanf("%d", &Q);

    for (int i = 0; i < Q; i++) {
      scanf("%d", &s);
      scanf("%d", &e);
      scanf("%d", &m);

      int count = 0;

      for (int j = s; j < e; j++) {
        count += record[m][j];
      }

      printf("%d\\n", count);
    }

    for (int i = 1; i <= M; i++) {
      for (int j = 540; j < 1260; j++) {
        record[i][j] = 0;
      }
    }
  }

  return 0;
}