#include <bits/stdc++.h>
#define FR(i, N) for (int i = 0; i < int(N); i++)
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
const int MAXN = 200000;
int nukes[MAXN][4];
void construct(vector<vector<ll>>& res, int R, int C) {
res.clear();
res.resize(R, vector<ll>(C, 0));
}
void add(vector<vector<ll>>& res, int r, int c, ll v) {
if (r < res.size() && c < res[0].size() && r >= 0 && c >= 0) {
res[r][c] += v;
}
}
ll get(vector<vector<ll>>& res, int r, int c) {
if (r < res.size() && c < res[0].size() && r >= 0 && c >= 0) {
return res[r][c];
}
return 0;
}
ll round(ll i, ll d) {
ll md = i%d;
if (i < (d+1)/2) {
return i/d;
}
else {
return (i+d-1)/d;
}
}
void pr(vector<vector<ll>>& res) {
for (int i = 0; i < res.size(); i++) {
for (int j = 0; j < res[0].size(); j++) {
cerr << res[i][j] << " ";
}
cerr << '\n';
}
}
int main() {
// freopen("input.in", "r", stdin);
cin.tie(0);
cin.sync_with_stdio(0);
int W, H;
cin >> W >> H;
int N;
cin >> N;
FR(i, N) {
cin >> nukes[i][1] >> nukes[i][0] >> nukes[i][2] >> nukes[i][3];
nukes[i][1]--;
nukes[i][0]--;
}
vector<vector<ll>> diagLeft;
vector<vector<ll>> diagRight;
vector<vector<ll>> hori;
vector<vector<ll>> pref;
vector<vector<ll>> initial;
construct(diagLeft, H, W);
construct(diagRight, H, W);
construct(hori, H, W);
construct(pref, H, W);
construct(initial, H, W);
FR(i, N) {
int s = (nukes[i][2] - 1)/nukes[i][3];
int st = nukes[i][2] - s*nukes[i][3];
add(diagLeft, nukes[i][0]-s, nukes[i][1]-s, -nukes[i][3]);
add(diagLeft, nukes[i][0]+s+1, nukes[i][1]+s+1, nukes[i][3]);
add(diagRight, nukes[i][0]-s, nukes[i][1]+s, -nukes[i][3]);
add(diagRight, nukes[i][0]+s+1, nukes[i][1]-s-1, nukes[i][3]);
add(hori, nukes[i][0]-s, nukes[i][1]-s, nukes[i][3]);
add(hori, nukes[i][0]-s, nukes[i][1]+s+1, -nukes[i][3]);
add(hori, nukes[i][0]+s, nukes[i][1]-s, nukes[i][3]);
add(hori, nukes[i][0] + s, nukes[i][1]+s+1, -nukes[i][3]);
add(initial, nukes[i][0]-s, nukes[i][1]-s, st);
add(initial, nukes[i][0]+s+1, nukes[i][1]-s, -st);
add(initial, nukes[i][0]-s, nukes[i][1]+s+1,-st);
add(initial, nukes[i][0]+s+1, nukes[i][1]+s+1, st);
}
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
hori[i][j] += get(hori, i, j-1);
diagLeft[i][j] += get(diagLeft, i-1, j-1);
diagRight[i][j] += get(diagRight, i-1, j+1);
initial[i][j] += - get(initial, i-1, j-1) + get(initial, i-1, j) + get(initial, i, j-1);
pref[i][j] = hori[i][j] + diagLeft[i][j] + diagRight[i][j] + get(pref, i-1, j);
}
}
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
pref[i][j] += get(pref, i-1, j);
initial[i][j] += get(pref, i-1, j);
}
}
// pr(initial);
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
initial[i][j] += - get(initial, i-1, j-1) + get(initial, i-1, j) + get(initial, i, j-1);
}
}
int Q;
cin >> Q;
FR(i, Q) {
int r1, r2, c1, c2;
cin >> c1 >> r1 >> c2 >> r2;
c1--, r1--, c2--, r2--;
cout << round(get(initial, r2, c2) - get(initial, r1-1, c2) - get(initial, r2, c1-1) + get(initial, r1-1, c1-1), (r2-r1+1)*(c2-c1+1)) << '\n';
}
return 0;
}
Compilation message
nuclearia.cpp: In function 'void add(std::vector<std::vector<long long int> >&, int, int, ll)':
nuclearia.cpp:16:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | if (r < res.size() && c < res[0].size() && r >= 0 && c >= 0) {
| ~~^~~~~~~~~~~~
nuclearia.cpp:16:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | if (r < res.size() && c < res[0].size() && r >= 0 && c >= 0) {
| ~~^~~~~~~~~~~~~~~
nuclearia.cpp: In function 'll get(std::vector<std::vector<long long int> >&, int, int)':
nuclearia.cpp:21:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | if (r < res.size() && c < res[0].size() && r >= 0 && c >= 0) {
| ~~^~~~~~~~~~~~
nuclearia.cpp:21:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | if (r < res.size() && c < res[0].size() && r >= 0 && c >= 0) {
| ~~^~~~~~~~~~~~~~~
nuclearia.cpp: In function 'll round(ll, ll)':
nuclearia.cpp:27:8: warning: unused variable 'md' [-Wunused-variable]
27 | ll md = i%d;
| ^~
nuclearia.cpp: In function 'void pr(std::vector<std::vector<long long int> >&)':
nuclearia.cpp:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for (int i = 0; i < res.size(); i++) {
| ~~^~~~~~~~~~~~
nuclearia.cpp:37:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int j = 0; j < res[0].size(); j++) {
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
191 ms |
117760 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
162 ms |
117760 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
144 ms |
98408 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
208 ms |
122732 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
272 ms |
118144 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
171 ms |
47832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
269 ms |
100892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
176 ms |
43812 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
341 ms |
121344 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
367 ms |
121344 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
429 ms |
103456 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
460 ms |
103764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
360 ms |
106664 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
350 ms |
103232 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |