This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |