#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define f first
#define s second
#define oo 1000000000
int main() {
int w, h; cin >> w >> h;
int n; cin >> n;
vector<vector<ll>> rad(w+1, vector<ll>(h+1));
for (int i = 0; i < n; ++i) {
int x, y; ll a, b; cin >> x >> y >> a >> b;
for (int j = 1; j <= w; ++j) {
for (int k = 1; k <= h; ++k) {
rad[j][k] += 1ll * max(0ll, 1ll * a - 1ll * b * max(abs(j - x), abs(k - y)));
}
}
}
vector<vector<ll>> pref(w+1, vector<ll>(h+1));
for (int i = 1; i <= w; ++i) {
for (int j = 1; j <= h; ++j) {
pref[i][j] = pref[i-1][j] + pref[i][j-1] - pref[i-1][j-1] + rad[i][j];
}
}
int q; cin >> q;
for (int i = 0; i < q; ++i) {
int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
ll cur = pref[x2][y2] - pref[x2][y1 - 1] - pref[x1 - 1][y2] + pref[x1 - 1][y1 - 1];
ll cnt = (x2 - x1 + 1) * (y2 - y1 + 1);
//cerr << cur << " " << cnt << "\n";
ll res = cur / cnt;
ll k = cnt / 2;
if (cnt % 2 == 0) k++;
if (cur % cnt >= k) res++;
cout << res << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
833 ms |
274328 KB |
Output is correct |
2 |
Incorrect |
503 ms |
2704 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
847 ms |
274232 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
227 ms |
39876 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
225 ms |
42408 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1070 ms |
276360 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1099 ms |
111780 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
824 ms |
42004 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1014 ms |
57540 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1094 ms |
137260 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1087 ms |
137320 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1090 ms |
20044 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1093 ms |
19916 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1091 ms |
20556 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1093 ms |
20044 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |