#include <bits/stdc++.h>
using namespace std;
#define ll long long
//14:20
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int h,w,n,q;
cin >> w >> h >> n;
vector<pair<pair<int,int>,pair<ll,ll> > > plant(n);
for(int i = 0; i < n; i++) {
cin >> plant[i].first.first >> plant[i].first.second >> plant[i].second.first >> plant[i].second.second;
}
vector<vector<ll> > table(w+2,vector<ll>(h+2,0));
for(int i = 1; i <= w; i++) {
for(int j = 1; j <= h; j++) {
for(int p = 0; p < n; p++) {
table[i][j]+= max(0LL,plant[p].second.first-plant[p].second.second*(max(abs(i-plant[p].first.first),abs(j-plant[p].first.second))));
}
}
}
vector<vector<ll> > preftable(w+2,vector<ll>(h+2,0));
for(int i = 1; i <= w; i++) {
for(int j = 1; j <= h; j++) {
preftable[i][j] = preftable[i-1][j]+preftable[i][j-1]-preftable[i-1][j-1]+table[i][j];
}
}
cin >> q;
while(q--) {
int x1,x2,y1,y2;
cin >> x1 >> y1 >> x2 >> y2;
ll ans = preftable[x2][y2]-preftable[x1-1][y2]-preftable[x2][y1-1]+preftable[x1-1][y1-1];
ll are = (y2-y1+1)*(x2-x1+1);
ll an = ans/are;
if(ans-an*are >= (an+1)*are-ans) {
an++;
}
cout << an << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
853 ms |
274304 KB |
Output is correct |
2 |
Correct |
95 ms |
274304 KB |
Output is correct |
3 |
Correct |
123 ms |
274304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
847 ms |
275148 KB |
Output is correct |
2 |
Correct |
128 ms |
275148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
461 ms |
275148 KB |
Output is correct |
2 |
Correct |
96 ms |
275148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
399 ms |
275148 KB |
Output is correct |
2 |
Correct |
97 ms |
275148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
871 ms |
281032 KB |
Output is correct |
2 |
Correct |
93 ms |
281032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
753 ms |
281032 KB |
Output is correct |
2 |
Correct |
85 ms |
281032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
535 ms |
281032 KB |
Output is correct |
2 |
Correct |
89 ms |
281032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
689 ms |
281032 KB |
Output is correct |
2 |
Correct |
99 ms |
281032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1091 ms |
281032 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1091 ms |
281032 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1083 ms |
281032 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1088 ms |
281032 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1093 ms |
281032 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1081 ms |
281032 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |