#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
signed 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] += max(0ll, a - b * max(1ll * abs(j - x), 1ll * 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 = 1ll * (x2 - x1 + 1) * (y2 - y1 + 1);
//cerr << cur << " " << cnt << "\n";
ll res = cur / cnt;
ll k = cnt / 2;
if (cnt % 2 == 1) k++;
if (cur % cnt >= k) res++;
cout << res << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
828 ms |
274232 KB |
Output is correct |
2 |
Correct |
500 ms |
2684 KB |
Output is correct |
3 |
Correct |
487 ms |
2372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
876 ms |
274228 KB |
Output is correct |
2 |
Correct |
510 ms |
2740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
229 ms |
39760 KB |
Output is correct |
2 |
Correct |
494 ms |
2628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
223 ms |
42428 KB |
Output is correct |
2 |
Correct |
496 ms |
2628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1080 ms |
276472 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1090 ms |
111548 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
833 ms |
42188 KB |
Output is correct |
2 |
Correct |
512 ms |
2884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
995 ms |
57372 KB |
Output is correct |
2 |
Correct |
488 ms |
2580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1090 ms |
137200 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1088 ms |
137172 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1074 ms |
20044 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1075 ms |
19916 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1092 ms |
20556 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1093 ms |
20016 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |