#include <bits/stdc++.h>
using namespace std;
void solve(){
bool swp = 0;
int w,h;
cin >> w >> h;
if(w < h){
swp = 1;
swap(w,h);
}
long long arr[h+5][h+w+5];
long long pre[h+5][h+w+5];
for(int i=0;i<h+5;i++){
for(int j = 0;j<h+w+5;j++){
arr[i][j] = pre[i][j] = 0;
}
}
int n;
cin >> n;
for(int i=0;i<n;i++){
int x,y,a,b;
cin >> x >> y >> a >> b;
if(swp)swap(x,y);
x += h;
for(int i=1;i<=h;i++){
int dif = abs(y-i);
if(dif * b > a)continue;
arr[i][max(1,x-dif+1)] -= b;
arr[i][max(1,x-(a/b)+1)] += b;
arr[i][max(1,x-(a/b))] += a - b*(x - max(1,x-(a/b)));
arr[i][max(1,x-(a/b)) + 1] -= a - b*(x - max(1,x-(a/b)));
arr[i][min(w+h+1,x+dif+1)] -= b;
arr[i][min(w+h+1,x+(a/b)+1)] += b;
arr[i][min(w+h+1,x+(a/b)+1)] -= a%b;
}
}
for(int i=1;i<=h;i++){
for(int j=1;j<=w+h;j++){
arr[i][j] += arr[i][j-1];
}
}
for(int i=1;i<=h;i++){
for(int j=1;j<=w+h;j++){
arr[i][j] += arr[i][j-1];
}
}
for(int i=1;i<=h;i++){
for(int j=h+1;j<=w+h;j++){
pre[i][j] = pre[i-1][j] + pre[i][j-1] - pre[i-1][j-1]+arr[i][j];
}
}
int q;
cin >> q;
while(q--){
int x1,y1,x2,y2;
cin >> x1 >> y1 >> x2 >> y2;
if(!swp)swap(x1,y1),swap(x2,y2);
y1 += h;
y2 += h;
long double cnt = (x2-x1+1) * (y2 -y1+1);
cout <<(long long) ((pre[x2][y2] - pre[x2][y1-1] - pre[x1 -1][y2] + pre[x1-1][y1-1])/cnt + 0.5) << endl;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t=1;
//cin>>t;
while(t--){
solve();
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
159 ms |
235116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
159 ms |
235244 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
43884 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
49316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
723 ms |
238892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
613 ms |
98284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
600 ms |
47980 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
588 ms |
59372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
807 ms |
239020 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
837 ms |
239072 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1082 ms |
45556 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1065 ms |
56540 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1096 ms |
42944 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1094 ms |
44524 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |