#include<bits/stdc++.h>
using namespace std;
int N, Q, W, H;
vector<vector<long long int>> plants, preSum;
void print(vector<vector<long long int>>& V){
for(int i = 0; i < W; ++i){
for(int j = 0; j < H; ++j){
cout << V[i][j] << " ";
}
cout << endl;
}
}
void calcPreSum(){
preSum = vector<vector<long long int>>(W, vector<long long int>(H, 0));
for(int i = 0; i < W; ++i){
preSum[i][0] = plants[i][0];
if(i) preSum[i][0] += preSum[i-1][0];
}
for(int i = 0; i < H; ++i){
preSum[0][i] = plants[0][i];
if(i) preSum[0][i] += preSum[0][i-1];
}
for(int i = 1; i < W; ++i){
for(int j = 1; j < H; ++j){
preSum[i][j] = plants[i][j] + preSum[i-1][j] + preSum[i][j-1] - preSum[i-1][j-1];
}
}
//print(preSum);
}
long long getSum(int x1, int y1, int x2, int y2){
long long ans = preSum[x2][y2];
//cout << ans << endl;
if(x1 > 0 and y1 > 0){
ans += preSum[x1 - 1][y1 - 1] - preSum[x1 - 1][y2] - preSum[x2][y1 - 1];
return ans;
}else if (x1) ans -= preSum[x1 - 1][y2];
else if(y1) ans -= preSum[x2][y1 - 1];
return ans;
}
int main(){
int x, y, a, b;
cin >> W >> H;
plants = vector<vector<long long int>>(W, vector<long long int>(H, 0));
cin >> N;
for(int i = 0; i < N; ++i){
cin >> x >> y >> a >> b;
x--; y--;
plants[x][y] += a;
for(int d = 1; d*b < a; ++d){
//print();
//cout << endl;
//cout << a << " " << d << endl;
if(y >= d){
for(int i = max(0, x-d); i < min(W, x+d); ++i){
plants[i][y-d] += a - b*d;
}
}
if(x+d < W){
for(int i = max(0, y-d); i < min(H, y+d); ++i)plants[x+d][i] += a - b*d;
}
if(y+d < H){
for(int i = min(W-1, x+d); i > max(-1, x-d); --i)plants[i][y+d] += a - b*d;
}
if(x >= d){
for(int i = min(H-1, y+d); i > max(-1, y-d); --i)plants[x-d][i] += a - b*d;
}
}
}
//print();
calcPreSum();
cin >> Q;
while(Q--){
int x1, x2, y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
x1--; y1--; x2--; y2--;
long long sum = getSum(x1, y1, x2, y2);
//cout << sum << endl;
long long numSquares = (x2 - x1 + 1)*(y2 - y1 + 1);
long double q = (long double)sum/(long double)numSquares;
//if(q*numSquares < sum) q++;
cout << round(q) << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
610 ms |
274252 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
558 ms |
274260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
80 ms |
39816 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1022 ms |
40416 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
956 ms |
280332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
955 ms |
115708 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
696 ms |
45236 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
757 ms |
60808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1077 ms |
137268 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1062 ms |
137276 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1068 ms |
20792 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1070 ms |
20188 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1068 ms |
20436 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1061 ms |
20100 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |