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

#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 100000;
int cnt[1000][1000][3];
int fld[1000][1000];
int main() {
  int h, w, k;
  char t;
  cin >> h >> w >> k;
  REP(i, h) REP(j, w) {
    cin >> t;
    fld[j][i] = t == 'J' ? 0 : t == 'O' ? 1 : 2;
  }
  cnt[0][0][fld[0][0]]++;
  REP(i, w)
  REP(j, 3) if (i != 0) cnt[i][0][j] =
      cnt[i - 1][0][j] + (fld[i][0] == j ? 1 : 0);
  REP(i, h)
  REP(j, 3) if (i != 0) cnt[0][i][j] =
      cnt[0][i - 1][j] + (fld[0][i] == j ? 1 : 0);
  REP(i, w) REP(j, h) {
    if (i == 0 || j == 0)
      continue;
    REP(k, 3)
    cnt[i][j][k] = cnt[i - 1][j][k] + cnt[i][j - 1][k] - cnt[i - 1][j - 1][k] +
                   (fld[i][j] == k ? 1 : 0);
  }
  // REP(i,h)REP(j,w)printf("%d%c",cnt[j][i][0],j==w-1?'\\n':' ');
  int a, b, c, d;
  while (k--) {
    cin >> a >> b >> c >> d;
    a--;
    b--;
    c--;
    d--;
    int ans[3];
    REP(i, 3) ans[i] = cnt[d][c][i];
    if (a != 0)
      REP(i, 3) ans[i] -= cnt[d][a - 1][i];
    if (b != 0)
      REP(i, 3) ans[i] -= cnt[b - 1][c][i];
    if (a != 0 && b != 0)
      REP(i, 3) ans[i] += cnt[b - 1][a - 1][i];
    REP(i, 3) printf("%d%c", ans[i], i == 2 ? '\\n' : ' ');
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, m, k, ans[3];
  int a, b, c, d;
  char data[1000][1000];
  cin >> m >> n;
  cin >> k;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      cin >> data[j][i];
    }
  }
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < 3; j++) {
      ans[j] = 0;
    }
    cin >> a >> b >> c >> d;
    for (int y = a - 1; y < c; y++) {
      for (int x = b - 1; x < d; x++) {
        if (data[x][y] == 'J')
          ans[0]++;
        else if (data[x][y] == 'O')
          ans[1]++;
        else
          ans[2]++;
      }
    }
    cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
  }
}
Problem p00483 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int MAX = 1001;
int H, W, K;
int J[MAX][MAX], O[MAX][MAX], I[MAX][MAX];
char field[MAX][MAX];

int main(void) {
  while (cin >> H >> W >> K) {
    memset(J, 0, sizeof(J));
    memset(O, 0, sizeof(O));
    memset(I, 0, sizeof(I));

    for (int i = 1; i <= H; i++) {
      cin >> &field[i][1];
      for (int j = 1; j <= W; j++) {
        J[i][j] = J[i - 1][j] + J[i][j - 1] - J[i - 1][j - 1];
        O[i][j] = O[i - 1][j] + O[i][j - 1] - O[i - 1][j - 1];
        I[i][j] = I[i - 1][j] + I[i][j - 1] - I[i - 1][j - 1];

        if (field[i][j] == 'J')
          J[i][j]++;
        else if (field[i][j] == 'O')
          O[i][j]++;
        else if (field[i][j] == 'I')
          I[i][j]++;
      }
    }

    for (int i = 0; i < K; i++) {
      int px, py, qx, qy;
      cin >> px >> py >> qx >> qy;
      int ansJ, ansO, ansI;
      ansJ = J[qx][qy] - J[px - 1][qy] - J[qx][py - 1] + J[px - 1][py - 1];
      ansO = O[qx][qy] - O[px - 1][qy] - O[qx][py - 1] + O[px - 1][py - 1];
      ansI = I[qx][qy] - I[px - 1][qy] - I[qx][py - 1] + I[px - 1][py - 1];
      printf("%d %d %d\\n", ansJ, ansO, ansI);
    }
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
int main(void) {
  int M, N, K;
  char res[1001][1001];
  int xp, yp, xq, yq;
  int J, O, I;

  cin >> M >> N;
  cin >> K;
  for (int i = 0; i < M; i++) {
    scanf("%s", res[i]);
  }

  for (int a = 0; a < K; a++) {
    cin >> xp >> yp >> xq >> yq;
    J = 0;
    O = 0;
    I = 0;
    for (int i = xp - 1; i < xq; i++) {
      for (int j = yp - 1; j < yq; j++) {
        if (res[i][j] == 'J')
          J++;
        if (res[i][j] == 'O')
          O++;
        if (res[i][j] == 'I')
          I++;
        // cout << res[i][j] << ' ';
      }
      // cout << endl;
    }
    printf("%d %d %d\\n", J, O, I);
  }
  return 0;
}
Problem p00483 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

const int MAX = 1001;

int sumj[MAX][MAX], sumo[MAX][MAX], sumi[MAX][MAX];
char data[MAX][MAX];
int x, y;

void make() {
  for (int i = 1; i <= y; i++) {
    for (int j = 1; j <= x; j++) {
      sumj[i][j] = sumj[i - 1][j] + sumj[i][j - 1] - sumj[i - 1][j - 1];
      sumo[i][j] = sumo[i - 1][j] + sumo[i][j - 1] - sumo[i - 1][j - 1];
      sumi[i][j] = sumi[i - 1][j] + sumi[i][j - 1] - sumi[i - 1][j - 1];
      if (data[i][j] == 'J')
        sumj[i][j]++;
      if (data[i][j] == 'O')
        sumo[i][j]++;
      if (data[i][j] == 'I')
        sumi[i][j]++;
    }
  }
}

int main() {
  cin >> y >> x;
  string trash;
  int num;
  cin >> num;
  for (int i = 1; i <= y; i++)
    for (int j = 1; j <= x; j++)
      cin >> data[i][j];
  make();
  for (int i = 0; i < num; i++) {
    int po[4];
    cin >> po[0] >> po[1] >> po[2] >> po[3];
    cout << sumj[po[2]][po[3]] - sumj[po[2]][po[1] - 1] -
                sumj[po[0] - 1][po[3]] + sumj[po[0] - 1][po[1] - 1]
         << " ";
    cout << sumo[po[2]][po[3]] - sumo[po[2]][po[1] - 1] -
                sumo[po[0] - 1][po[3]] + sumo[po[0] - 1][po[1] - 1]
         << " ";
    cout << sumi[po[2]][po[3]] - sumi[po[2]][po[1] - 1] -
                sumi[po[0] - 1][po[3]] + sumi[po[0] - 1][po[1] - 1]
         << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

  int m, n;
  scanf("%d %d", &m, &n);
  string data[m];

  int k;
  scanf("%d", &k);
  string trash;
  getline(cin, trash);
  for (int i = 0; i < m; i++) {
    getline(cin, data[i]);
  }

  for (int i = 0; i < k; i++) {
    int sum[3] = {0, 0, 0};
    int row[2], col[2];
    scanf("%d %d %d %d", &row[0], &col[0], &row[1], &col[1]);
    for (int r = row[0] - 1; r < row[1]; r++) {
      /*for(int c = col[0]-1;  c < col[1]; c++){
        if(data[r][c] == 'J') sum[0]++;
        if(data[r][c] == 'O') sum[1]++;
        if(data[r][c] == 'I') sum[2]++;
        }*/
      // cout <<"data[r]   "  <<data[r] << endl;
      string sub = data[r].substr(col[0] - 1, col[1] - col[0] + 1);
      // cout << sub << endl;
      sort(sub.begin(), sub.end());
      int x = 0;
      while (sub[x] == 'I') {
        sum[2]++;
        x++;
      }
      while (sub[x] == 'J') {
        sum[0]++;
        x++;
      }
      sum[1] += sub.length() - x;
    }
    printf("%d %d %d\\n", sum[0], sum[1], sum[2]);
  }
  return 0;
}
Problem p00483 (C++) — buggy submission, verdict: Time Limit Exceeded

// Solution for aoj 0560:Planetary Exploration
#include <iostream>
using namespace std;
int n, m, k, res[3], mid, a, b;
int planet2[1001][1001][4], ex[4];
char planet[1001][1001];
int jud(char a) {
  if (a == 'J')
    return 1;
  if (a == 'O')
    return 2;
  if (a == 'I')
    return 3;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> planet[i][j];
    }
  }
  planet2[1][1][jud(planet[1][1])] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j < 4; j++)
      planet2[i][1][j] = planet2[i - 1][1][j];
    planet2[i][1][jud(planet[i][1])]++;
  }
  for (int i = 2; i <= m; i++) {
    for (int j = 1; j < 4; j++)
      planet2[1][i][j] = planet2[1][i - 1][j];
    planet2[1][i][jud(planet[1][i])]++;
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 2; j <= m; j++) {
      for (int l = 1; l < 4; l++) {
        planet2[i][j][l] = planet2[i - 1][j][l] + planet2[i][j - 1][l] -
                           planet2[i - 1][j - 1][l];
      }
      planet2[i][j][jud(planet[i][j])]++;
    }
  }
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < 4; j++) {
      cin >> ex[j];
    }
    for (int j = 1; j < 4; j++) {
      cout << planet2[ex[2]][ex[3]][j] - planet2[ex[0] - 1][ex[3]][j] -
                  planet2[ex[2]][ex[1] - 1][j] +
                  planet2[ex[0] - 1][ex[1] - 1][j];
      if (j != 3)
        cout << ' ';
    }
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

// Solution for aoj 0560:Planetary Exploration
#include <iostream>
using namespace std;
int n, m, k, res[3];
int exp[4];
char planet[1001][1001];
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> planet[i][j];
    }
  }
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < 4; j++) {
      cin >> exp[j];
    }
    for (int j = 0; j < 3; j++) {
      res[j] = 0;
    }
    for (int j = exp[0]; j <= exp[2]; j++) {
      for (int l = exp[1]; l <= exp[3]; l++) {
        if (planet[j][l] == 'J')
          res[0]++;
        if (planet[j][l] == 'O')
          res[1]++;
        if (planet[j][l] == 'I')
          res[2]++;
      }
    }
    cout << res[0] << ' ' << res[1] << ' ' << res[2] << endl;
  }
  return 0;
}
Problem p00483 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int m, n;
  int k;
  cin >> m >> n;
  cin >> k;
  char q;
  vector<vector<int>> hyouJ(m + 1, vector<int>(n + 1));
  vector<vector<int>> hyouO(m + 1, vector<int>(n + 1));
  vector<vector<int>> hyouI(m + 1, vector<int>(n + 1));
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> q;
      hyouJ[i][j] = hyouJ[i][j - 1];
      hyouO[i][j] = hyouO[i][j - 1];
      hyouI[i][j] = hyouI[i][j - 1];
      if (q == 'J') {
        hyouJ[i][j]++;
      } else if (q == 'O') {
        hyouO[i][j]++;
      } else {
        hyouI[i][j]++;
      }
    }
  }
  for (int i = 0; i < k; i++) {
    int counter[3] = {0};
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    for (int j = a; j <= c; j++) {
      counter[0] += (hyouJ[j][d] - hyouJ[j][b - 1]);
      counter[1] += (hyouO[j][d] - hyouO[j][b - 1]);
      counter[2] += (hyouI[j][d] - hyouI[j][b - 1]);
    }
    cout << counter[0] << ' ' << counter[1] << ' ' << counter[2] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int m, n;
  int k;
  cin >> m >> n;
  cin >> k;
  vector<vector<char>> hyou(m, vector<char>(n));
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      cin >> hyou[i][j];
    }
  }
  for (int i = 0; i < k; i++) {
    int counter[3] = {0};
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    for (int j = a - 1; j < c; j++) {
      for (int t = b - 1; t < d; t++) {
        if (hyou[j][t] == 'J') {
          counter[0]++;
        } else if (hyou[j][t] == 'O') {
          counter[1]++;
        } else {
          counter[2]++;
        }
      }
    }
    cout << counter[0] << ' ' << counter[1] << ' ' << counter[2] << endl;
  }
  return 0;
}
Problem p00483 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
using namespace std;

const int MAX_N = 1000;
int J[MAX_N + 1][MAX_N + 1];
int O[MAX_N + 1][MAX_N + 1];
int I[MAX_N + 1][MAX_N + 1];
char input[MAX_N + 10][MAX_N + 10];
int N, M, K;
int plus_j, plus_o, plus_i;
int a, b, c, d;
int res_j, res_o, res_i;

int main() {
  scanf("%d%d", &M, &N);
  scanf("%d", &K);
  for (int i = 0; i < M; i++) {
    scanf("%s", input[i]);
  }

  for (int i = 0; i <= M; i++) {
    for (int j = 0; j <= N; j++) {
      if (i == 0 || j == 0) {
        J[i][j] = 0;
        O[i][j] = 0;
        I[i][j] = 0;
      } else {
        plus_j = 0;
        plus_o = 0;
        plus_i = 0;
        if (input[i - 1][j - 1] == 'J')
          plus_j = 1;
        else if (input[i - 1][j - 1] == 'O')
          plus_o = 1;
        else if (input[i - 1][j - 1] == 'I')
          plus_i = 1;

        J[i][j] = J[i - 1][j] + J[i][j - 1] - J[i - 1][j - 1] + plus_j;
        O[i][j] = O[i - 1][j] + O[i][j - 1] - O[i - 1][j - 1] + plus_o;
        I[i][j] = I[i - 1][j] + I[i][j - 1] - I[i - 1][j - 1] + plus_i;
      }
    }
  }

  for (int i = 0; i < K; i++) {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    res_j = J[c][d] - (J[a - 1][d] + J[c][b - 1] - J[a - 1][b - 1]);
    res_o = O[c][d] - (O[a - 1][d] + O[c][b - 1] - O[a - 1][b - 1]);
    res_i = I[c][d] - (I[a - 1][d] + I[c][b - 1] - I[a - 1][b - 1]);
    printf("%d %d %d\\n", res_j, res_o, res_i);
  }

  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>
using namespace std;

int main() {
  const int MAX_N = 1000;
  int J[MAX_N + 1][MAX_N + 1];
  int O[MAX_N + 1][MAX_N + 1];
  int I[MAX_N + 1][MAX_N + 1];
  char input[MAX_N + 10][MAX_N + 10];
  int N, M, K;
  int plus_j, plus_o, plus_i;
  int a, b, c, d;
  int res_j, res_o, res_i;

  scanf("%d%d", &M, &N);
  scanf("%d", &K);
  for (int i = 0; i < M; i++) {
    scanf("%s", input[i]);
  }

  for (int i = 0; i <= M; i++) {
    for (int j = 0; j <= N; j++) {
      if (i == 0 || j == 0) {
        J[i][j] = 0;
        O[i][j] = 0;
        I[i][j] = 0;
      } else {
        plus_j = 0;
        plus_o = 0;
        plus_i = 0;
        if (input[i - 1][j - 1] == 'J')
          plus_j = 1;
        else if (input[i - 1][j - 1] == 'O')
          plus_o = 1;
        else if (input[i - 1][j - 1] == 'I')
          plus_i = 1;

        J[i][j] = J[i - 1][j] + J[i][j - 1] - J[i - 1][j - 1] + plus_j;
        O[i][j] = O[i - 1][j] + O[i][j - 1] - O[i - 1][j - 1] + plus_o;
        I[i][j] = I[i - 1][j] + I[i][j - 1] - I[i - 1][j - 1] + plus_i;
      }
    }
  }

  for (int i = 0; i < K; i++) {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    res_j = J[c][d] - (J[a - 1][d] + J[c][b - 1] - J[a - 1][b - 1]);
    res_o = O[c][d] - (O[a - 1][d] + O[c][b - 1] - O[a - 1][b - 1]);
    res_i = I[c][d] - (I[a - 1][d] + I[c][b - 1] - I[a - 1][b - 1]);
    printf("%d %d %d\\n", res_j, res_o, res_i);
  }

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

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;

//// < "D:\\D_Download\\Visual Studio
///2015\\Projects\\programing_contest_c++\\Debug\\a.txt"
int main() {
  int M, N;
  cin >> M >> N;
  int K;
  cin >> K;
  map<char, int> mp;
  mp['J'] = 0;
  mp['O'] = 1;
  mp['I'] = 2;
  vector<vector<vector<int>>> sums(M + 1,
                                   vector<vector<int>>(N + 1, vector<int>(3)));
  for (int i = 0; i < M; ++i) {
    string st;
    cin >> st;
    for (int j = 0; j < N; ++j) {
      sums[i + 1][j + 1][mp[st[j]]]++;
    }
  }
  for (int k = 0; k < 3; ++k) {
    for (int i = 1; i <= M; ++i) {
      for (int j = 1; j <= N; ++j) {
        sums[i][j][k] +=
            sums[i][j - 1][k] + sums[i - 1][j][k] - sums[i - 1][j - 1][k];
      }
    }
  }
  for (int i = 0; i < K; ++i) {
    int a, b, c, d;
    cin >> b >> a >> d >> c;
    b--;
    a--;
    vector<int> anss(3);
    for (int j = 0; j < 3; ++j) {
      anss[j] = sums[d][c][j] - sums[d][a][j] - sums[b][c][j] + sums[b][a][j];
    }
    cout << anss[0] << " " << anss[1] << " " << anss[2] << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;

//// < "D:\\D_Download\\Visual Studio
///2015\\Projects\\programing_contest_c++\\Debug\\a.txt"
int main() {
  int M, N;
  cin >> M >> N;
  int K;
  cin >> K;
  map<char, int> mp;
  mp['J'] = 0;
  mp['O'] = 1;
  mp['I'] = 2;
  vector<vector<vector<int>>> nums(M + 1,
                                   vector<vector<int>>(N + 1, vector<int>(3)));
  vector<vector<vector<int>>> sums(M + 1,
                                   vector<vector<int>>(N + 1, vector<int>(3)));
  for (int i = 0; i < M; ++i) {
    string st;
    cin >> st;
    for (int j = 0; j < N; ++j) {
      nums[i + 1][j + 1][mp[st[j]]]++;
    }
  }
  for (int i = 1; i <= M; ++i) {
    for (int j = 1; j <= N; ++j) {
    }
  }
  for (int k = 0; k < 3; ++k) {
    for (int i = 1; i <= M; ++i) {
      for (int j = 1; j <= N; ++j) {
        sums[i][j][k] = sums[i][j - 1][k] + sums[i - 1][j][k] -
                        sums[i - 1][j - 1][k] + nums[i][j][k];
      }
    }
  }
  nums.clear();
  for (int i = 0; i < K; ++i) {
    int a, b, c, d;
    cin >> b >> a >> d >> c;
    b--;
    a--;
    vector<int> anss(3);
    for (int j = 0; j < 3; ++j) {
      anss[j] = sums[d][c][j] - sums[d][a][j] - sums[b][c][j] + sums[b][a][j];
    }
    cout << anss[0] << " " << anss[1] << " " << anss[2] << endl;
  }
  return 0;
}
Problem p00483 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int m, n, k;
int f, g, h;
int a, b, c, d;
char map[1003][1003];
int j[1003][1003], o[1003][1003], i[1003][1003];
int main(void) {
  scanf("%d %d", &m, &n);
  scanf("%d", &k);
  for (f = 1; f <= m; f++) {
    for (g = 1; g <= n; g++) {
      j[f][g] = 0;
      o[f][g] = 0;
      i[f][g] = 0;
    }
  }
  for (f = 1; f <= m; f++) {
    for (g = 1; g <= n; g++) {
      scanf(" %c", &map[f][g]);
      if (map[f][g] == 'J') {
        j[f][g]++;
      } else if (map[f][g] == 'O') {
        o[f][g]++;
      } else if (map[f][g] == 'I') {
        i[f][g]++;
      }
      j[f][g + 1] += j[f][g];
      o[f][g + 1] += o[f][g];
      i[f][g + 1] += i[f][g];
    }
  }
  for (g = 1; g <= n; g++) {
    for (f = 1; f <= m; f++) {
      j[f + 1][g] += j[f][g];
      o[f + 1][g] += o[f][g];
      i[f + 1][g] += i[f][g];
    }
  }
  int anj, ano, ani;
  for (f = 0; f < k; f++) {
    scanf("%d %d %d %d", &a, &b, &c, &d);
    anj = j[c][d] - j[c][b - 1] - j[a - 1][d] + j[a - 1][b - 1];
    ano = o[c][d] - o[c][b - 1] - o[a - 1][d] + o[a - 1][b - 1];
    ani = i[c][d] - i[c][b - 1] - i[a - 1][d] + i[a - 1][b - 1];
    printf("%d %d %d\\n", anj, ano, ani);
  }
  /*for(f=1;f<=m;f++){
          for(g=1;g<=n;g++){
                  printf("%d,%d=%d%d%d ",f,g,j[f][g],o[f][g],i[f][g]);
          }
          printf("\\n");
  }*/
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
int m, n, k;
int f, g, h;
int a, b, c, d;
char map[1003][1003];
int j[1003][1003], o[1003][1003], i[1003][1003];
int main(void) {
  scanf("%d %d", &m, &n);
  scanf("%d", &k);
  for (f = 0; f < m; f++) {
    for (g = 0; g < n; g++) {
      j[f][g] = 0;
      o[f][g] = 0;
      i[f][g] = 0;
    }
  }
  for (f = 0; f < m; f++) {
    for (g = 0; g < n; g++) {
      scanf(" %c", &map[f][g]);
      if (map[f][g] == 'J') {
        j[f][g]++;
      } else if (map[f][g] == 'O') {
        o[f][g]++;
      } else if (map[f][g] == 'I') {
        i[f][g]++;
      }
      j[f][g + 1] += j[f][g];
      o[f][g + 1] += o[f][g];
      i[f][g + 1] += i[f][g];
    }
  }
  for (g = 0; g < n; g++) {
    for (f = 0; f < m; f++) {
      j[f + 1][g] += j[f][g];
      o[f + 1][g] += o[f][g];
      i[f + 1][g] += i[f][g];
    }
  }
  int anj, ano, ani;
  for (f = 0; f < k; f++) {
    scanf("%d %d %d %d", &a, &b, &c, &d);
    anj = j[c - 1][d - 1] - j[c - 1][b - 2] - j[a - 2][d - 1] + j[a - 2][b - 2];
    ano = o[c - 1][d - 1] - o[c - 1][b - 2] - o[a - 2][d - 1] + o[a - 2][b - 2];
    ani = i[c - 1][d - 1] - i[c - 1][b - 2] - i[a - 2][d - 1] + i[a - 2][b - 2];
    printf("%d %d %d\\n", anj, ano, ani);
  }
  /*for(f=0;f<m;f++){
          for(g=0;g<n;g++){
                  printf("%d,%d=%d%d%d ",f,g,j[f][g],o[f][g],i[f][g]);
          }
          printf("\\n");
  }*/
  return 0;
}
Problem p00483 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int m, n, k;
int J[1001][1001];
int O[1001][1001];
int I[1001][1001];

int main() {
  cin >> m >> n >> k;

  for (int i = 0; i <= m; i++) {
    J[0][i] = 0;
    O[0][i] = 0;
    I[0][i] = 0;
  }
  for (int i = 0; i <= n; i++) {
    J[i][0] = 0;
    O[i][0] = 0;
    I[i][0] = 0;
  }

  for (int y = 1; y <= m; y++) {
    int j = 0, o = 0, i = 0;
    for (int x = 1; x <= n; x++) {
      char c;
      cin >> c;
      switch (c) {
      case 'J':
        j++;
        break;
      case 'O':
        o++;
        break;
      case 'I':
        i++;
        break;
      }
      J[x][y] = J[x][y - 1] + j;
      O[x][y] = O[x][y - 1] + o;
      I[x][y] = I[x][y - 1] + i;
    }
  }

  while (k--) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << (J[d][c] - J[b - 1][c] - J[d][a - 1] + J[b - 1][a - 1]) << ' ';
    cout << (O[d][c] - O[b - 1][c] - O[d][a - 1] + O[b - 1][a - 1]) << ' ';
    cout << (I[d][c] - I[b - 1][c] - I[d][a - 1] + I[b - 1][a - 1]) << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int m, n, k;
int J[1001][1001];
int O[1001][1001];
int I[1001][1001];

int main() {
  cin >> m >> n >> k;

  for (int i = 0; i <= m; i++) {
    J[0][i] = 0;
    O[0][i] = 0;
    I[0][i] = 0;
  }
  for (int i = 0; i <= n; i++) {
    J[i][0] = 0;
    O[i][0] = 0;
    I[i][0] = 0;
  }

  for (int y = 1; y <= m; y++) {
    int j = 0, o = 0, i = 0;
    for (int x = 1; x <= n; x++) {
      int c;
      cin >> c;
      switch (c) {
      case 'J':
        j++;
        break;
      case 'O':
        o++;
        break;
      case 'I':
        i++;
        break;
      }
      J[x][y] = J[x][y - 1] + j;
      O[x][y] = O[x][y - 1] + o;
      I[x][y] = I[x][y - 1] + i;
    }
  }

  while (k--) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << (J[d][c] - J[b - 1][c] - J[b][a - 1]) << ' ';
    cout << (O[d][c] - O[b - 1][c] - O[b][a - 1]) << ' ';
    cout << (I[d][c] - I[b - 1][c] - I[b][a - 1]) << endl;
  }

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

#include <bits/stdc++.h>

#define int long long
#define rep(a, b, c) for (int a = b; a < c; a++)

using namespace std;

int waku[1003][1003][3];

void fir() {
  for (int i = 0; i < 1003; i++) {
    for (int j = 0; j < 1003; j++) {
      for (int k = 0; k < 3; k++) {
        waku[i][j][k] = 0;
      }
    }
  }
}

signed main() {
  char s;
  int w, h, n;
  fir();
  cin >> h >> w >> n;
  rep(i, 1, h + 1) {
    rep(j, 1, w + 1) {
      cin >> s;
      for (int k = 0; k < 3; k++)
        waku[i][j][k] +=
            (waku[i - 1][j][k] + waku[i][j - 1][k] - waku[i - 1][j - 1][k]);
      if (s == 'J') {
        waku[i][j][0]++;
      } else if (s == 'O') {
        waku[i][j][1]++;
      } else {
        waku[i][j][2]++;
      }
    }
  }
  /**
      debag
  rep(i,1,h+1){
      rep(j,1,w+1){
          cout << waku[i][j][0] << " ";
      }
      cout << endl;
  }
  */
  int ans[3];
  int lw, lh, rw, rh;
  rep(i, 0, n) {
    cin >> lw >> lh >> rw >> rh;
    rep(j, 0, 3) {
      ans[j] = waku[rw][rh][j] + waku[lw - 1][lh - 1][j] - waku[rw][lh - 1][j] -
               waku[lw - 1][rh][j];
    }
    cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>

#define int long long
#define rep(a, b, c) for (int a = b; a < c; a++)

using namespace std;

signed main() {
  char s;
  int waku[1003][1003][3];
  int w, h, n;
  cin >> h >> w >> n;
  rep(i, 1, h + 1) {
    rep(j, 1, w + 1) {
      cin >> s;
      for (int k = 0; k < 3; k++)
        waku[i][j][k] =
            (waku[i - 1][j][k] + waku[i][j - 1][k] - waku[i - 1][j - 1][k]);
      if (s == 'J') {
        waku[i][j][0]++;
      } else if (s == 'O') {
        waku[i][j][1]++;
      } else {
        waku[i][j][2]++;
      }
    }
  }
  int lw, lh, rw, rh;
  rep(i, 0, n) {
    cin >> lw >> lh >> rw >> rh;
    rep(j, 0, 3) {
      cout << waku[rw][rh][j] + waku[lw][lh][j] - waku[rw][lh][j] -
                  waku[lw][rh][j];
      if (j < 2)
        cout << " ";
      else
        cout << endl;
    }
  }
  return 0;
}