-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path11660.cpp
More file actions
62 lines (48 loc) · 1.05 KB
/
Copy path11660.cpp
File metadata and controls
62 lines (48 loc) · 1.05 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
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <bitset>
#define xx first
#define yy second
#define all(x) (x).begin(), (x).end()
using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
using iii = tuple<int, int, int>;
i64 mapv[1030][1030];
int main()
{
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
scanf("%lld", &mapv[i][j]);
for (int i = 1; i <= n; i++)
for (int j = 2; j <= n; j++)
mapv[j][i] += mapv[j-1][i];
for (int i = 1; i <= n; i++)
for (int j = 2; j <= n; j++)
mapv[i][j] += mapv[i][j - 1];
for (int i = 0; i < m; i++)
{
int x1, y1, x2, y2;
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
i64 sum = 0;
sum += mapv[x2][y2];
sum -= mapv[x1 - 1][y2];
sum -= mapv[x2][y1 - 1];
sum += mapv[x1 - 1][y1 - 1];
printf("%lld\n", sum);
}
return 0;
}