#include <bits/stdc++.h>
#define fin std::cin
#define fout std::cout
// std::ifstream fin("nuclearia.in");
// std::ofstream fout("nuclearia.out");
long long n, m;
long long **x, **c;
long long *line;
void update(long long i, long long left, long long right, long long value) {
if(left <= 0) {
line[i] += std::min(right - left + 1, -left + 1) * value;
left = 1;
}
right = std::max(right, 0LL);
right = std::min(right, m);
x[i][left] += value;
x[i][right+1] -= value;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
fin >> n >> m;
x = new long long* [n+5];
c = new long long* [n+5];
line = new long long [n+5];
for(long long i = 0; i<= n+4; i ++) {
x[i] = new long long[m+5];
c[i] = new long long[m+5];
}
long long plants;
fin >> plants;
for(long long p = 0; p < plants; p ++) {
long long pi, pj, a, b;
fin >> pi >> pj >> a >> b;
long long maxDist = (a - 1) / b;
long long dist, left, right;
long long x1 = pi - maxDist; x1 = std::max(x1, 1LL);
long long y1 = pj - maxDist; y1 = std::max(y1, 1LL);
long long x2 = pi + maxDist; x2 = std::min(x2, n);
long long y2 = pj + maxDist; y2 = std::min(y2, m);
long long add = a - (maxDist) * b;
c[x1][y1] += add;
c[x1][y2+1] -= add;
c[x2+1][y1] -= add;
c[x2+1][y2+1] += add;
maxDist --;
for(long long i = std::max(1LL, pi - maxDist); i <= std::min(n, pi + maxDist); i ++) {
dist = std::abs(i - pi);
//interval 1
left = pj - maxDist;
right = left + (maxDist - dist);
update(i, left, right, b);
//interval 3
right = pj + maxDist + 1;
left = pj + dist + 1;
update(i, left, right, -b);
}
}
for(long long i = 1; i <= n; i ++) {
for(long long j = 1; j <= m; j ++) {
x[i][j] += x[i][j-1];
c[i][j] = c[i][j] + c[i-1][j] + c[i][j-1] - c[i-1][j-1];
}
}
for(long long i = 1; i <= n; i ++) {
for(long long j = 1; j <= m; j ++) {
x[i][j] += x[i][j-1];
}
}
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= n; j++)
x[i][j] += line[i] + c[i][j];
long long sum[n+5][m+5] = {};
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++) {
sum[i][j] = x[i][j] + sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];
}
int Q;
fin >> Q;
while(Q --) {
int x1, y1, x2, y2;
fin >> x1 >> y1 >> x2 >> y2;
long long total = sum[x2][y2] - sum[x2][y1-1] - sum[x1-1][y2] + sum[x1-1][y1-1];
long long size = (x2 - x1 + 1) * (y2 - y1 + 1);
long long ans = total / size;
if(2 * (total % size) >= size)
ans += 1;
fout << ans << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
729 ms |
645984 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
616 ms |
689580 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
78 ms |
59792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
63 ms |
64164 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
618 ms |
712996 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
281 ms |
302160 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
162 ms |
64920 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
132 ms |
150908 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
586 ms |
721820 KB |
Execution killed with signal 11 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
582 ms |
729424 KB |
Execution killed with signal 11 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1090 ms |
43332 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1066 ms |
41652 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1082 ms |
26300 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1094 ms |
40296 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |