#include <iostream>
//#include <bits/stdc++.h>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef vector<ll> vi;
typedef vector<bool> vb;
const ll mm = 1000000007;
const int maxn = 2e5 + 1;
ll near(ll a, ll b) {
double a1 = a, b1 = b;
double d = a1 / b1;
if (d - floor(d) < 0.5) {
return floor(d);
}
else return ceil(d);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
ll w, h; cin >> w >> h;
vector<vi> p(h, vi(w));
ll n; cin >> n;
ll xn, yn, a, b;
for (int i = 0; i < n; i++) {
cin >> xn >> yn >> a >> b;
--yn, --xn;
//box
//p[yn][xn] = 1;
ll maxd = a / b;
//cout << "maxd: " << maxd << endl;
ll dis,xc=xn-maxd,yc=yn-maxd;
for (xc; xc <= xn + maxd; xc++) {
//cout << "xc: " << xc << endl;
if (xc < 0) continue;
else if (xc > w - 1) xc = xn + maxd + 1;
else {
for (yc; yc <= yn + maxd; yc++) {
//cout << "yc: " << yc << endl;
if (yc < 0) continue;
else if (yc > h - 1) yc = yn + maxd + 1;
else{
dis = max(abs(xc - xn), abs(yc - yn));
p[yc][xc] += a - b * dis;
}
}
yc = yn - maxd;
}
}
/*
cout << "tabelaa:" << endl;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cout << p[i][j] << " ";
}
cout << endl;
}
cout << endl;
*/
}
vector<vi> dp(h, vi(w));
dp[0][0] = p[0][0];
for (int j = 1; j < w; j++) {
dp[0][j] = p[0][j] + dp[0][j - 1];
}
for (int i = 1; i < h; i++) {
for (int j = 0; j < w; j++) {
if (j == 0) {
dp[i][j] = p[i][j] + dp[i - 1][j];
}
else {
dp[i][j] = p[i][j] + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
}
}
}
/*
cout << "dp tabelaa:" << endl;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cout << dp[i][j] << " ";
}
cout << endl;
}*/
ll q; cin >> q;
while (q--) {
ll x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2;
x1--; x2--; y1--; y2--;
ll A = (y2 - y1+1) * (x2 - x1+1);
ll S=0;
S += dp[y2][x2];
if (x1 > 0 and y1 > 0) {
S -= dp[y2][x1 - 1];
S -= dp[y1 - 1][x2];
S += dp[y1 - 1][x1 - 1];
}
else if (x1 == 0 and y1 == 0) {
}
else if (x1 == 0) {
S -= dp[y1 - 1][x2];
}
else if (y1 == 0) {
S -= dp[y2][x1 - 1];
}
//cout << "SiA: " << S << " i " << A << endl;
cout << near(S, A) << endl;
}
return 0;
}
Compilation message
nuclearia.cpp: In function 'int main()':
nuclearia.cpp:46:14: warning: statement has no effect [-Wunused-value]
46 | for (xc; xc <= xn + maxd; xc++) {
| ^~
nuclearia.cpp:51:22: warning: statement has no effect [-Wunused-value]
51 | for (yc; yc <= yn + maxd; yc++) {
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1062 ms |
39516 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1040 ms |
39396 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
820 ms |
39516 KB |
Output is correct |
2 |
Correct |
241 ms |
4468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
443 ms |
49232 KB |
Output is correct |
2 |
Correct |
237 ms |
4692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1076 ms |
39516 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1054 ms |
15964 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
728 ms |
45652 KB |
Output is correct |
2 |
Correct |
245 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1049 ms |
12120 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1062 ms |
39516 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1025 ms |
39512 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1014 ms |
20560 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1020 ms |
20072 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1078 ms |
20572 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1018 ms |
20056 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |