Language: C++

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 4;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

class Land { 
public:
	int J, O, I;
	Land(int j = 0, int o = 0, int i = 0) {
		J = j;
		O = o;
		I = i;
	}
	Land operator + (Land other) {
		Land res(0, 0, 0);
		res.J = J + other.J;
		res.O = O + other.O;
		res.I = I + other.I;
		return res;
	}
};

int main() {
	int w, h, k, i, j;
	cin >> h >> w >> k;
	vs a(h);
	for (i = 0; i < h; i++) {
		cin >> a[i];
	}
	Land z();
	vector< vector<Land> > sum(h + 1, vector<Land>(w + 1, z));
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			sum[i + 1][j + 1] = sum[i + 1][j];
			switch (a[i][j]) {
			case 'J':
				sum[i + 1][j + 1].J++;
				break;
			case'O':
				sum[i + 1][j + 1].O++;
				break;
			default:
				sum[i + 1][j + 1].I++;
			}
		}
		for (j = 0; j < w; j++) {
			sum[i + 1][j + 1] = sum[i + 1][j + 1] + sum[i][j + 1];
		}
	}
	/*
	for (i = 0; i <= h; i++) {
		for (j = 0; j <= w; j++) {
			cout << sum[i][j].J << sum[i][j].O << sum[i][j].I << " ";
		}
		cout << endl;
	}
	*/
	for (i = 0; i < k; i++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		int J = 0, O = 0, I = 0;
		J = sum[c][d].J - sum[c][b - 1].J - sum[a - 1][d].J + sum[a - 1][b - 1].J;
		O = sum[c][d].O - sum[c][b - 1].O - sum[a - 1][d].O + sum[a - 1][b - 1].O;
		I = sum[c][d].I - sum[c][b - 1].I - sum[a - 1][d].I + sum[a - 1][b - 1].I;
		cout << J << " " << O << " " << I << endl;
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:50:15: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   50 |         Land z();
      |               ^~
a.cc:50:15: note: remove parentheses to default-initialize a variable
   50 |         Land z();
      |               ^~
      |               --
a.cc:50:15: note: or replace parentheses with braces to value-initialize a variable
a.cc:51:64: error: no matching function for call to 'std::vector<Land>::vector(int, Land (&)())'
   51 |         vector< vector<Land> > sum(h + 1, vector<Land>(w + 1, z));
      |                                                                ^
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:569:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(size_type, const value_type&, const allocator_type&) [with _Tp = Land; _Alloc = std::allocator<Land>; size_type = long unsigned int; value_type = Land; allocator_type = std::allocator<Land>]' (near match)
  569 |       vector(size_type __n, const value_type& __value,
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:569:7: note:   conversion of argument 2 would be ill-formed:
a.cc:51:63: error: invalid user-defined conversion from 'Land()' to 'const std::vector<Land>::value_type&' {aka 'const Land&'} [-fpermissive]
   51 |         vector< vector<Land> > sum(h + 1, vector<Land>(w + 1, z));
      |                                                               ^
a.cc:29:9: note: candidate is: 'Land::Land(int, int, int)' (near match)
   29 |         Land(int j = 0, int o = 0, int i = 0) {
      |         ^~~~
a.cc:29:9: note:   conversion of argument 1 would be ill-formed:
a.cc:51:63: error: invalid conversion from 'Land (*)()' to 'int' [-fpermissive]
   51 |         vector< vector<Land> > sum(h + 1, vector<Land>(w + 1, z));
      |                                                               ^
      |                                                               |
      |                                                               Land (*)()
a.cc:51:63: error: invalid conversion from 'Land (*)()' to 'int' [-fpermissive]
   51 |         vector< vector<Land> > sum(h + 1, vector<Land>(w + 1, z));
      |                                                               ^
      |                                                               |
      |                                                               Land (*)()
a.cc:29:18: note:   initializing argument 1 of 'Land::Land(int, int, int)'
   29 |         Land(int j = 0, int o = 0, int i = 0) {
      |              ~~~~^~~~~
/usr/include/c++/14/bits/stl_vector.h:707:9: note: candidate: 'template<class _InputIterator, class> std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with <template-parameter-2-2> = _InputIterator; _Tp = Land; _Alloc = std::allocator<Land>]'
  707 |         vector(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:707:9: note:   template argument deduction/substitution failed:
a.cc:51:64: note:   deduced conflicting types for parameter '_InputIterator' ('int' and 'Land (*)()')
   51 |         vector< vector<Land> > sum(h + 1, vector<Land>(w + 1, z));
      |                                                                ^
/usr/include/c++/14/bits/stl_vector.h:678:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::initializer_list<_Tp>, const allocator_type&) [with _Tp = Land; _Alloc = std::allocator<Land>; allocator_type = std::allocator<Land>]'
  678 |       vector(initializer_list<value_type> __l,
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:678:43: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<Land>'
  678 |       vector(initializer_list<value_type> __l,
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:659:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, std::__type_identity_t<_Alloc>&) [with _Tp = Land; _Alloc = std::allocator<Land>; std::__type_identity_t<_Alloc> = std::allocator<Land>]'
  659 |       vector(vector&& __rv, const __type_identity_t<allocator_type>& __m)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:659:23: note:   no known conversion for argument 1 from 'int' to 'std::vector<Land>&&'
  659 |       vector(vector&& __rv, const __type_identity_t<allocator_type>& __m)
      |              ~~~~~~~~~^~~~
/usr/include/c++/14/bits/stl_vector.h:640:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&, std::false_type) [with _Tp = Land; _Alloc = std::allocator<Land>; allocator_type = std::allocator<Land>; std::false_type = std::false_type]'
  640 |       vector(vector&& __rv, const allocator_type& __m, false_type)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:640:7: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_vector.h:635:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&, std::true_type) [with _Tp = Land; _Alloc = std::allocator<Land>; allocator_type = std::allocator<Land>; std::true_type = std::true_type]'
  635 |       vector(vector&& __rv, const allocator_type& __m, true_type) noexcept
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:635:7: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_vector.h:624:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&, std::__type_identity_t<_Alloc>&) [with _Tp = Land; _Alloc = std::allocator<Land>; std::__type_identity_t<_Alloc> = std::allocator<Land>]'
  624 |       vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:624:28: note:   no known conversion for argument 1 from 'int' to 'const std::vector<Land>&'
  624 |       vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
      |              ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:620:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&) [with _Tp = Land; _Alloc = std::allocator<Land>]'
  620 |       vector(vector&&) noexcept = default;
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:620:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:601:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = Land; _Alloc = std::allocator<Land>]'
  601 |       vector(const vector& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:601:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:556:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(size_type, const allocator_type&) [with _Tp = Land; _Alloc = std::allocator<Land>; size_type = long unsigned int; allocator_type = std::allocator<Land>]'
  556 |       vector(size_type __n, const allocator_type& __a = allocator_type())
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:556:51: note:   no known conversion for argument 2 from 'Land()' to 'const std::vector<Land>::allocator_type&' {aka 'const std::allocator<Land>&'}
  556 |       vector(size_type __n, const allocator_type& __a = allocator_type())
      |                             ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:542:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = Land; _Alloc = std::allocator<Land>; allocator_type = std::allocator<Land>]'
  542 |       vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:542:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:531:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector() [with _Tp = Land; _Alloc = std::allocator<Land>]'
  531 |       vector() = default;
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:531:7: note:   candidate expects 0 arguments, 2 provided