#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);
bool Inverse = 0;
int n, m;
cin >> n >> m;
if (n > m) {
Inverse = 1;
swap(n, m);
}
assert(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;
if (Inverse) {
swap(r1, c1);
}
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;
if (Inverse) {
swap(r1, c1);
swap(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";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
186 ms |
58964 KB |
Output is correct |
2 |
Correct |
56 ms |
2640 KB |
Output is correct |
3 |
Correct |
53 ms |
2284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
188 ms |
58988 KB |
Output is correct |
2 |
Correct |
59 ms |
2700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
172 ms |
19964 KB |
Output is correct |
2 |
Correct |
55 ms |
2616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
170 ms |
21844 KB |
Output is correct |
2 |
Correct |
60 ms |
2716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
58912 KB |
Output is correct |
2 |
Correct |
60 ms |
2892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
282 ms |
23732 KB |
Output is correct |
2 |
Correct |
56 ms |
2628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
272 ms |
22400 KB |
Output is correct |
2 |
Correct |
58 ms |
2860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
251 ms |
15956 KB |
Output is correct |
2 |
Correct |
53 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1080 ms |
58976 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1078 ms |
58956 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1086 ms |
19924 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1066 ms |
19924 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1085 ms |
20692 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1089 ms |
19924 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |