|
| 1 | +```java |
| 2 | +import java.io.BufferedReader; |
| 3 | +import java.io.IOException; |
| 4 | +import java.io.InputStreamReader; |
| 5 | +import java.util.StringTokenizer; |
| 6 | + |
| 7 | +public class Main{ |
| 8 | + public static void main(String[] args)throws IOException{ |
| 9 | + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 10 | + StringTokenizer st = new StringTokenizer(br.readLine()); |
| 11 | + int N = Integer.parseInt(st.nextToken()); |
| 12 | + int M = Integer.parseInt(st.nextToken()); |
| 13 | + int K = Integer.parseInt(br.readLine()); |
| 14 | + int[][] J = new int[N+1][M+1]; |
| 15 | + int[][] O = new int[N+1][M+1]; |
| 16 | + int[][] I = new int[N+1][M+1]; |
| 17 | + |
| 18 | + |
| 19 | + for(int r = 1; r<=N; r++){ |
| 20 | + String line = br.readLine(); |
| 21 | + for(int c = 1 ; c<=M; c++){ |
| 22 | + char ch = line.charAt(c-1); |
| 23 | + |
| 24 | + J[r][c] = J[r-1][c] + J[r][c-1] - J[r-1][c-1]; |
| 25 | + O[r][c] = O[r-1][c] + O[r][c-1] - O[r-1][c-1]; |
| 26 | + I[r][c] = I[r-1][c] + I[r][c-1] - I[r-1][c-1]; |
| 27 | + if(ch == 'J') |
| 28 | + J[r][c]++; |
| 29 | + else if(ch == 'O') |
| 30 | + O[r][c]++; |
| 31 | + else |
| 32 | + I[r][c]++; |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + StringBuilder sb = new StringBuilder(); |
| 37 | + for(int i=0; i<K; i++){ |
| 38 | + st = new StringTokenizer(br.readLine()); |
| 39 | + int a = Integer.parseInt(st.nextToken()); |
| 40 | + int b = Integer.parseInt(st.nextToken()); |
| 41 | + int c = Integer.parseInt(st.nextToken()); |
| 42 | + int d = Integer.parseInt(st.nextToken()); |
| 43 | + int j = J[c][d] - J[a-1][d] - J[c][b-1] + J[a-1][b-1]; |
| 44 | + int o = O[c][d] - O[a-1][d] - O[c][b-1] + O[a-1][b-1]; |
| 45 | + int ii = I[c][d] - I[a-1][d] - I[c][b-1] + I[a-1][b-1]; |
| 46 | + |
| 47 | + sb.append(j).append(" ").append(o).append(" ").append(ii).append("\n"); |
| 48 | + } |
| 49 | + |
| 50 | + System.out.print(sb); |
| 51 | + } |
| 52 | +} |
| 53 | +``` |
0 commit comments