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 int long long
struct plant {
int x, y, a, b;
};
void printans(int total, int area) {
int gcd = __gcd(total, area);
total /= gcd;
area /= gcd;
if(area == 2) {
cout << total / 2 + 1 << "\n";
return;
}
cout << total / area + ((total % area <= area / 2) ? 0 : 1) << "\n";
}
int w, h;
int n;
int q;
vector<int> suffpref;
vector<int> suff;
vector<int> suffplus;
vector<int> rad;
vector<int> pref;
vector<plant> plants;
void solve() {
cin >> w >> h;
suffpref.assign(1 + w + 1, 0);
suff.assign(1 + w + 1, 0);
suffplus.assign(1 + w + 1, 0);
rad.assign(1 + w + 1, 0);
pref.assign(1 + w + 1, 0);
cin >> n;
plants.resize(n);
for(int i = 0; i < n; i++) {
cin >> plants[i].x >> plants[i].y >> plants[i].a >> plants[i].b;
}
for(plant p : plants) {
int x = p.x, a = p.a, b = p.b;
int l = max(1ll, x - a / b), r = min(w, x + a / b);
suffplus[r] += a % b;
suffplus[l - 1] -= a % b;
//cout << l << " " << r << " " << a % b << "\n";
a -= a % b;
//int r0 = a % b, r1 = max(0ll, a - b * (x - 1)), rw = max(0ll, a - b * (w - x));
int cnt = a / b;
//cout << cnt << " " << a << " " << b << "\n";
if(x + cnt - 1 <= w) {
suffpref[x + cnt - 1] += b;
suffpref[x - 1] -= b;
} else {
suffpref[w] += b;
suffpref[x - 1] -= b;
suffplus[w] += b * (x + cnt - 1 - w);
}
if(x - cnt >= 0) {
suffpref[x - 1] -= b;
suffpref[max(x - cnt - 1, 0ll)] += b;
} else {
suffpref[x - 1] -= b;
}
}
for(int i = w; i >= 1; i--) {
suff[i] += suffpref[i] + suff[i + 1];
}
for(int i = 1; i <= w; i++) {
suff[i] += suffplus[i];
}
for(int i = w; i >= 1; i--) {
rad[i] = rad[i + 1] + suff[i];
}
for(int i = 1; i <= w; i++) {
pref[i] = rad[i] + pref[i - 1];
}
/*for(int i = 1; i <= w; i++) {
cout << suffpref[i] << " ";
}
cout << "\n";
for(int i = 1; i <= w; i++) {
cout << suff[i] << " ";
}
cout << "\n";
for(int i = 1; i <= w; i++) {
cout << rad[i] << " ";
}
cout << "\n";*/
cin >> q;
for(int i = 0; i < q; i++) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
int total = pref[x2] - pref[x1 - 1];
int area = (x2 - x1 + 1);
printans(total, area);
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
}
# | 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... |