#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX_N = 200005;
const int MOD = 998244353;
vector<vector<int>>grid, pref;
void solve() {
int w, h;
cin >> w >> h;
grid.assign(w, vector<int>(h, 0));
pref.assign(w, vector<int>(h, 0));
int n;
cin >> n;
for(int i=0; i<n; ++i) {
int x, y, a, b;
cin >> x >> y >> a >> b;
--x, --y;
int cnt = a/b;
for(int j=max(0LL, x-cnt); j<=min(w-1, x+cnt); ++j) {
for(int k=max(0LL, y-cnt); k<=min(h-1, y+cnt); ++k) {
grid[j][k] += max(0LL,a - b * max(abs(k-y), abs(j-x)));
}
}
}
for(int i=w-1; i>=0; --i) {
for(int j=h-1; j>=0; --j) {
pref[i][j] = grid[i][j];
if(j+1<h) pref[i][j] += pref[i][j+1];
if(i+1<w) pref[i][j] += pref[i+1][j];
if(i+1<w && j+1<h) pref[i][j] -= pref[i+1][j+1];
}
}
int q;
cin >> q;
while(q--) {
long double x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
--x1, --y1, --x2, --y2;
long double sum = pref[x1][y1];
if(x2+1<w) sum -= pref[x2+1][y1];
if(y2+1<h) sum -= pref[x1][y2+1];
if(x2+1<w && y2+1<h) sum += pref[x2+1][y2+1];
long double x = sum/((x2-x1+1)*(y2-y1+1));
cout << lround(x) << endl;
}
}
signed main() {
int t = 1;
while(t--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
671 ms |
274404 KB |
Output is correct |
2 |
Correct |
428 ms |
2676 KB |
Output is correct |
3 |
Correct |
418 ms |
2352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
552 ms |
274388 KB |
Output is correct |
2 |
Correct |
460 ms |
2660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
195 ms |
39772 KB |
Output is correct |
2 |
Correct |
381 ms |
3816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
228 ms |
40480 KB |
Output is correct |
2 |
Correct |
425 ms |
4180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
843 ms |
276564 KB |
Output is correct |
2 |
Correct |
455 ms |
3000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1012 ms |
112288 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
771 ms |
42040 KB |
Output is correct |
2 |
Correct |
420 ms |
4084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
822 ms |
57560 KB |
Output is correct |
2 |
Correct |
421 ms |
3800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1060 ms |
274304 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1065 ms |
274256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1034 ms |
39768 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1047 ms |
39516 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1061 ms |
40120 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1065 ms |
39772 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |