#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<vector<int> > hori;
vector<vector<int> > vert;
vector<vector<int> > suffplus;
vector<vector<int> > suff;
vector<vector<int> > rad;
vector<vector<int> > pref;
vector<plant> plants;
void solve() {
cin >> w >> h;
hori.assign(1 + w + 1, vector<int> (1 + h + 1, 0));
vert.assign(1 + w + 1, vector<int> (1 + h + 1, 0));
suffplus.assign(1 + w + 1, vector<int> (1 + h + 1, 0));
suff.assign(1 + w + 1, vector<int> (1 + h + 1, 0));
rad.assign(1 + w + 1, vector<int> (1 + h + 1, 0));
pref.assign(1 + w + 1, vector<int> (1 + h + 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, y = p.y, a = p.a, b = p.b;
int x1 = x - a / b, x2 = x + a / b, y1 = y - a / b, y2 = y + a / b;
suffplus[x2][y2] += a % b;
suffplus[max(x1 - 1, 0ll)][y2] -= a % b;
suffplus[x2][max(y1 - 1, 0ll)] -= a % b;
suffplus[max(x1 - 1, 0ll)][max(y1 - 1, 0ll)] += a % b;
a -= a % b;
x2--;
y2--;
vert[x2][y2] += b;
vert[max(x1 - 1, 0ll)][max(y1 - 1, 0ll)] -= b;
hori[x2][y1] -= b;
hori[max(x1 - 1, 0ll)][y2 + 1] += b;
}
for(int i = w; i >= 1; i--) {
for(int j = 1; j <= h; j++) {
vert[i][j] += vert[i + 1][j + 1];
hori[i][j] += hori[i + 1][j - 1];
suff[i][j] = hori[i][j] + vert[i][j];
}
}
for(int i = 1; i <= w; i++) {
for(int j = 1; j <= w; j++) {
suff[i][j] += suffplus[i][j];
}
}
for(int i = w; i >= 1; i--) {
for(int j = h; j >= 1; j--) {
rad[i][j] = suff[i][j] + rad[i + 1][j] + rad[i][j + 1] - rad[i + 1][j + 1];
}
}
for(int i = 1; i <= w; i++) {
for(int j = 1; j <= h; j++) {
pref[i][j] = rad[i][j] + pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1];
}
}
/*for(int i = 1; i <= w; i++) {
for(int j = 1; j <= h; j++) {
cout << hori[i][j] << " ";
}
cout << "\n";
}
cout << "----------\n";
for(int i = 1; i <= w; i++) {
for(int j = 1; j <= h; j++) {
cout << vert[i][j] << " ";
}
cout << "\n";
}
cout << "----------\n";
for(int i = 1; i <= w; i++) {
for(int j = 1; j <= h; j++) {
cout << suff[i][j] << " ";
}
cout << "\n";
}
cout << "----------\n";
for(int i = 1; i <= w; i++) {
for(int j = 1; j <= h; j++) {
cout << rad[i][j] << " ";
}
cout << "\n";
}
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][y2] - pref[x1 - 1][y2] - pref[x2][y1 - 1] + pref[x1 - 1][y1 - 1];
int area = (y2 - y1 + 1) * (x2 - x1 + 1);
printans(total, area);
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2751 ms |
1048580 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3104 ms |
1048576 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
144 ms |
241868 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
192 ms |
264572 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2896 ms |
1048576 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
479 ms |
667188 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
156 ms |
239924 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
298 ms |
429044 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3040 ms |
1048576 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3043 ms |
1048576 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
225 ms |
258100 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
215 ms |
256592 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
209 ms |
259504 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
197 ms |
257620 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |