#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#define sz(x) ((int)size(x))
#define trace(x) cout << #x << ": " << (x) << endl;
typedef long long ll;
const int N = 200000;
int x[N], y[N], a[N], b[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int nn, mm, n;
cin >> nn >> mm >> n;
for (int i = 0; i < n; ++i) {
cin >> x[i] >> y[i] >> a[i] >> b[i];
--x[i], --y[i];
}
vector<vector<ll>> v(nn, vector<ll>(mm)), pref(nn, vector<ll>(mm));
for (int k = 0; k < n; ++k) {
for (int i = 0; i < nn; ++i) {
for (int j = 0; j < mm; ++j) {
v[i][j] += max(0ll, a[k] - b[k] * (ll) max(abs(i - x[k]), abs(j - y[k])));
}
}
}
for (int i = 0; i < nn; ++i) {
for (int j = 0; j < mm; ++j) {
pref[i][j] = v[i][j];
if (i) pref[i][j] += pref[i - 1][j];
if (j) pref[i][j] += pref[i][j - 1];
if (i && j) pref[i][j] -= pref[i - 1][j - 1];
}
}
auto get = [&pref](int x1, int y1, int x2, int y2) {
ll ans = pref[x2][y2];
if (x1) ans -= pref[x1 - 1][y2];
if (y1) ans -= pref[x2][y1 - 1];
if (x1 && y1) ans += pref[x1 - 1][y1 - 1];
return ans;
};
int q;
cin >> q;
for (int i = 0; i < q; ++i) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
--x1, --y1, --x2, --y2;
ll sum = get(x1, y1, x2, y2);
ll S = (x2 - x1 + 1) * (ll) (y2 - y1 + 1);
cout << (sum * 2 / S + 1) / 2 << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
749 ms |
274316 KB |
Output is correct |
2 |
Correct |
54 ms |
4680 KB |
Output is correct |
3 |
Correct |
59 ms |
3880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
740 ms |
274384 KB |
Output is correct |
2 |
Correct |
57 ms |
4592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
186 ms |
39856 KB |
Output is correct |
2 |
Correct |
54 ms |
4320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
187 ms |
40568 KB |
Output is correct |
2 |
Correct |
54 ms |
4664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
506 ms |
280276 KB |
Output is correct |
2 |
Correct |
64 ms |
5324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
693 ms |
115744 KB |
Output is correct |
2 |
Correct |
56 ms |
4628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
289 ms |
45224 KB |
Output is correct |
2 |
Correct |
62 ms |
4912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
457 ms |
60900 KB |
Output is correct |
2 |
Correct |
55 ms |
4312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1102 ms |
281176 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1098 ms |
281252 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1073 ms |
47220 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1077 ms |
46948 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1086 ms |
46924 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1073 ms |
46924 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |