#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
/// freopen ("input.txt", "r", stdin);
int n, m;
cin >> n >> m;
vector<vector<ll>> radiation(n + 1, vector<ll> (m + 1, 0));
int ops;
cin >> ops;
for (int i = 1; i <= ops; i++) {
int r1, c1, a, b;
cin >> r1 >> c1 >> a >> b;
for (int r = 1; r <= n; r++) {
for (int c = 1; c <= m; c++) {
int dist = max(abs(r - r1), abs(c - c1));
radiation[r][c] += max(0LL, a - 1LL * b * dist);
}
}
}
{
/// transform the radiation in the form of prefix rectangle sum
for (int i = 1; i <= n; i++) {
ll cur = 0;
for (int j = 1; j <= m; j++) {
cur += radiation[i][j];
radiation[i][j] = radiation[i - 1][j] + cur;
}
}
}
int q;
cin >> q;
while (q--) {
int r1, c1, r2, c2;
cin >> r1 >> c1 >> r2 >> c2;
ll total = radiation[r2][c2] - radiation[r1 - 1][c2] - radiation[r2][c1 - 1] + radiation[r1 - 1][c1 - 1];
ll area = (r2 - r1 + 1) * (c2 - c1 + 1);
cout << total / area + (total % area >= area - total % area) << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
602 ms |
137164 KB |
Output is correct |
2 |
Correct |
56 ms |
4556 KB |
Output is correct |
3 |
Correct |
54 ms |
3808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
606 ms |
137292 KB |
Output is correct |
2 |
Correct |
57 ms |
4552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
175 ms |
20068 KB |
Output is correct |
2 |
Correct |
54 ms |
4300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
172 ms |
21844 KB |
Output is correct |
2 |
Correct |
56 ms |
4560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
378 ms |
139600 KB |
Output is correct |
2 |
Correct |
65 ms |
5176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
624 ms |
57416 KB |
Output is correct |
2 |
Correct |
56 ms |
4552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
263 ms |
22364 KB |
Output is correct |
2 |
Correct |
57 ms |
4824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
405 ms |
30020 KB |
Output is correct |
2 |
Correct |
53 ms |
4344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1101 ms |
137284 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1099 ms |
137288 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1089 ms |
20052 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1096 ms |
19924 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1095 ms |
20692 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1052 ms |
20052 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |