#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> > 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));
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;
suff[x2][y2] += a % b;
suff[max(x1 - 1, 0ll)][y2] -= a % b;
suff[x2][max(y1 - 1, 0ll)] -= a % b;
suff[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 = 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();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2013 ms |
1048580 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2817 ms |
1048576 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
113 ms |
201812 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
135 ms |
220792 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2999 ms |
1048576 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
338 ms |
556112 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
121 ms |
200016 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
226 ms |
357552 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2940 ms |
1048576 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2939 ms |
1048576 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
176 ms |
108784 KB |
Output is correct |
2 |
Correct |
177 ms |
114512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
182 ms |
108116 KB |
Output is correct |
2 |
Correct |
176 ms |
114512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
161 ms |
216100 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
152 ms |
214352 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |