This documentation is automatically generated by online-judge-tools/verification-helper
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/0560"
#include "../../../template/template.hpp"
#include "../../../data-structure/CumulativeSum2D.hpp"
const string t = "JOI";
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n,m,K;
cin >> n >> m >> K;
vector<CumulativeSum2D<int>> cnt(3, CumulativeSum2D<int>(n, m));
rep(i, n){
string s; cin >> s;
rep(j, m){
rep(k, 3) if(s[j] == t[k]){
cnt[k].set(i, j, 1);
break;
}
}
}
rep(i, 3) cnt[i].build();
rep(_, K){
int a,b,c,d;
cin >> a >> b >> c >> d;
a--; b--;
rep(i, 3) cout << cnt[i].query(a, b, c, d) << " \n"[i == 2];
}
}
#line 1 "test/aoj/JOI/Planetary-Exploration.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/0560"
#line 1 "template/template.hpp"
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <bitset>
#include <cctype>
#include <climits>
#include <functional>
#include <cassert>
#include <numeric>
#include <cstring>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define per(i, n) for(int i = (n) - 1; i >= 0; i--)
using ll = long long;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
constexpr int mod = 1000000007;
using namespace std;
template<class T, class U>
bool chmax(T &a, const U &b){ return a < b ? (a = b, 1) : 0; }
template<class T, class U>
bool chmin(T &a, const U &b){ return a > b ? (a = b, 1) : 0; }
#line 4 "test/aoj/JOI/Planetary-Exploration.test.cpp"
#line 1 "data-structure/CumulativeSum2D.hpp"
template <class T>
struct CumulativeSum2D {
CumulativeSum2D(const int h, const int w) : h(h), w(w), a(h+1, vector<T>(w+1)){}
CumulativeSum2D(const vector<vector<T>> &v) : h(v.size()), w(v[0].size()), a(h+1, vector<T>(w+1)){
for(int i = 0; i < h; i++)
for(int j = 0; j < w; j++) a[i + 1][j + 1] = v[i][j];
}
void set(const int i, const int j, const T x){
assert(0 <= i && i < h);
assert(0 <= j && j < w);
a[i + 1][j + 1] += x;
}
void build(){
for(int i = 0; i < h; i++)
for(int j = 0; j < w; j++)
a[i + 1][j + 1] += a[i + 1][j] + a[i][j + 1] - a[i][j];
}
T query(const int ly, const int lx, const int ry, const int rx) const{
assert(0 <= ly && ly <= ry && ry <= h);
assert(0 <= lx && lx <= rx && rx <= w);
return a[ry][rx] - a[ry][lx] - a[ly][rx] + a[ly][lx];
}
private:
int h, w;
vector<vector<T>> a;
};
#line 6 "test/aoj/JOI/Planetary-Exploration.test.cpp"
const string t = "JOI";
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n,m,K;
cin >> n >> m >> K;
vector<CumulativeSum2D<int>> cnt(3, CumulativeSum2D<int>(n, m));
rep(i, n){
string s; cin >> s;
rep(j, m){
rep(k, 3) if(s[j] == t[k]){
cnt[k].set(i, j, 1);
break;
}
}
}
rep(i, 3) cnt[i].build();
rep(_, K){
int a,b,c,d;
cin >> a >> b >> c >> d;
a--; b--;
rep(i, 3) cout << cnt[i].query(a, b, c, d) << " \n"[i == 2];
}
}