-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMain.java
46 lines (37 loc) Β· 1.48 KB
/
Main.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
package DP.P11660;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static int N, M;
static int[][] nums;
public static void main(String[] args) throws Exception {
System.setIn(new FileInputStream("src/DP/P11660/input.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
nums = new int[N][N];
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
for (int j = 0; j < N; j++) {
if (j == 0) nums[i][j] = Integer.parseInt(st.nextToken());
else nums[i][j] = nums[i][j-1] + Integer.parseInt(st.nextToken());
}
}
for (int i = 0; i < M; i++) {
st = new StringTokenizer(br.readLine());
int x1 = Integer.parseInt(st.nextToken()) - 1;
int y1 = Integer.parseInt(st.nextToken()) - 1;
int x2 = Integer.parseInt(st.nextToken()) - 1;
int y2 = Integer.parseInt(st.nextToken()) - 1;
int ans = 0;
for (int j = x1; j <= x2; j++) {
if (y1 > 0) ans += nums[j][y2] - nums[j][y1 - 1];
else ans += nums[j][y2];
}
System.out.println(ans);
}
}
}