#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();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
98140 KB |
Output is correct |
2 |
Correct |
43 ms |
4092 KB |
Output is correct |
3 |
Correct |
36 ms |
3404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
98140 KB |
Output is correct |
2 |
Correct |
42 ms |
4176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
102452 KB |
Output is correct |
2 |
Correct |
57 ms |
4432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
44008 KB |
Output is correct |
2 |
Correct |
43 ms |
3920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
51 ms |
4688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
60 ms |
24404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
127 ms |
112452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
149 ms |
112464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
96 ms |
14420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
96 ms |
14364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
95 ms |
14184 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
89 ms |
14420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |