-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBOJ11660.java
55 lines (45 loc) · 1.59 KB
/
BOJ11660.java
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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
static BufferedReader br;
static StringTokenizer st;
static StringBuilder sb;
static int n, m;
static int[][] board;
static int[][] dp;
static int x1, y1, x2, y2;
public static void main(String[] args) {
br = new BufferedReader(new InputStreamReader(System.in));
try{
st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
sb=new StringBuilder();
board=new int[1025][1025];
dp=new int[1025][1025];
for (int i=1; i<=n; i++){
st = new StringTokenizer(br.readLine());
for (int j=1; j<=n; j++) {
board[i][j] = Integer.parseInt(st.nextToken());
dp[i][j]=board[i][j]+dp[i][j-1];
}
}
for(int i=1; i<=m; i++){
int sum=0;
st = new StringTokenizer(br.readLine());
x1=Integer.parseInt(st.nextToken());
y1=Integer.parseInt(st.nextToken());
x2=Integer.parseInt(st.nextToken());
y2=Integer.parseInt(st.nextToken());
for(int x=x1; x<=x2; x++)
sum+=dp[x][y2]-dp[x][y1-1];
sb.append(sum).append("\n");
}
System.out.println(sb);
}catch (Exception e){
System.out.println(e);
System.exit(0);
}
}
}