-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforestqueries.java
More file actions
82 lines (71 loc) · 1.9 KB
/
forestqueries.java
File metadata and controls
82 lines (71 loc) · 1.9 KB
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
73
74
75
76
77
78
79
80
81
82
/*
ID: grifync1
LANG: JAVA
PROG: forestqueries
*/
//lil lil peezy
import java.util.*;
import java.io.*;
public class forestqueries {
public static int conv(String s) {
return Integer.parseInt(s);
}
public static int max(int a, int b) {
return Math.max(a, b);
}
public static int min(int a, int b) {
return Math.min(a, b);
}
public static void print(int num) {
System.out.println(num);
}
public static void prints(String s) {
System.out.println(s);
}
public static void printa(int[] a) {
for (int i = 0; i < a.length; i++) {
if (i == 0) {
System.out.print(a[i]);
} else {
System.out.print(" " + a[i]);
}
}
}
public static int[] sort(int[] nums) {
Arrays.sort(nums);
return nums;
}
public static void main(String[] args) throws IOException {
//BufferedReader in = new BufferedReader(new FileReader("forestqueries.in"));
//PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("forestqueries.out")));
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
//StringTokenizer st = new StringTokenizer(in.readLine());
StringTokenizer st = new StringTokenizer(in.readLine());
int n = conv(st.nextToken());
int k = conv(st.nextToken());
int[][] forest = new int[n+1][n+1];
for(int i=0; i<n; i++) {
String s = in.readLine();
for(int j=0; j<n; j++) {
forest[i+1][j+1]=(s.charAt(j)=='.')?0:1;
}
}
int[][] fqs = new int[n+1][n+1];
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
fqs[i][j]=fqs[i-1][j]+fqs[i][j-1]-fqs[i-1][j-1]+forest[i][j];
}
}
for(int i=0; i<k; i++) {
st = new StringTokenizer(in.readLine());
int a = conv(st.nextToken());
int b = conv(st.nextToken());
int a1 = conv(st.nextToken());
int b1 = conv(st.nextToken());
out.println(fqs[a1][b1]-fqs[a-1][b1]-fqs[a1][b-1]+fqs[a-1][b-1]);
}
in.close();
out.close();
}
}