1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
| #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int J[1005][1005], O[1005][1005], I[1005][1005];
int main() {
int m, n, k;
cin >> m >> n >> k;
vector<string> v(m);
rep(i, m) cin >> v[i];
memset(J, 0, sizeof(J));
memset(O, 0, sizeof(O));
memset(I, 0, sizeof(I));
rep(i, m) {
rep(j, n) {
if(v[i][j] == 'J') J[i][j]++;
if(v[i][j] == 'O') O[i][j]++;
if(v[i][j] == 'I') I[i][j]++;
}
}
rep(i, m) {
REP(j, 1, n) {
J[i][j] += J[i][j-1];
O[i][j] += O[i][j-1];
I[i][j] += I[i][j-1];
}
}
rep(i, n) {
REP(j, 1, m) {
J[j][i] += J[j-1][i];
O[j][i] += O[j-1][i];
I[j][i] += I[j-1][i];
}
}
rep(i, k) {
int a, b, c, d;
cin >> a >> b >> c >> d;
a--;
b--;
c--;
d--;
cout << J[c][d] - (a-1 >= 0 ? J[a-1][d] : 0) - (b-1 >= 0 ? J[c][b-1] : 0) + (a-1 >= 0 && b -1 >= 0 ? J[a-1][b-1] : 0) << " ";
cout << O[c][d] - (a-1 >= 0 ? O[a-1][d] : 0) - (b-1 >= 0 ? O[c][b-1] : 0) + (a-1 >= 0 && b -1 >= 0 ? O[a-1][b-1] : 0) << " ";
cout << I[c][d] - (a-1 >= 0 ? I[a-1][d] : 0) - (b-1 >= 0 ? I[c][b-1] : 0) + (a-1 >= 0 && b -1 >= 0 ? I[a-1][b-1] : 0) << endl;
}
return 0;
}
|