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;
typedef long long ll;
int w, h, n, q;
vector<vector<ll>> grid, pref;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> w >> h >> n;
grid.assign(h+1, vector<ll>(w+1, 0));
pref.assign(h+1, vector<ll>(w+1, 0));
for(int i = 0; i < n; i++) {
ll x, y, a, b; cin >> x >> y >> a >> b;
for(int r = 1; r <= h; r++) {
for(int c = 1; c <= w; c++) {
grid[r][c] += max(0ll, a - b * (ll)max(abs(x - c), abs(y - r)));
}
}
}
for(int r = 1; r <= h; r++) {
for(int c = 1; c <= w; c++) {
pref[r][c] = pref[r-1][c] + pref[r][c-1] - pref[r-1][c-1] + grid[r][c];
}
}
cin >> q;
while(q--) {
ll r1, c1, r2, c2; cin >> c1 >> r1 >> c2 >> r2;
// cerr << r1 << ' ' << c1 << ' ' << r2 << ' ' << c2 << '\n';
double ans = pref[r2][c2] - pref[r1-1][c2] - pref[r2][c1-1] + pref[r1-1][c1-1];
ans /= (r2 - r1 + 1) * (c2 - c1 + 1);
cout << (ll)(ans+0.5) << '\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... |