#include<bits/stdc++.h>
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=2e5;
const ll inf=1e18;
const ll mod=1e9+7;
ll h,w;
vector<vector<ll>> p1,p2,p3;
void add(ll x,ll y,ll a,ll b)
{
ll r=(a-1)/b;
if(x+r>w||x-r<1||y+r>h||y-r<1) return;
// p1 p2 p3
// p1 la prefix sum cho a
// p2 la prefix sum cho b cheo 1
// p3 la prefix sum cho b cheo 2
p1[x-r][y-r]+=a-(r+1)*b;
p1[x+r+1][y-r]-=a-(r+1)*b;
p1[x-r][y+r+1]-=a-(r+1)*b;
p1[x+r+1][y+r+1]+=a-(r+1)*b;
p2[x-r][y-r]+=b;
p2[x+r+2][y+r+2]-=b;
p3[x-r][y+r+1]-=b;
p3[x+r+2][y-r-1]+=b;
}
ll n;
using ld=long double;
ll get(ll x1,ll y1,ll x2,ll y2)
{
return p1[x2][y2]-p1[x1-1][y2]-p1[x2][y1-1]+p1[x1-1][y1-1];
}
void solve()
{
cin >> w >> h;
p1.resize(w+10,vector<ll>(h+10));
p2.resize(w+10,vector<ll>(h+10));
p3.resize(w+10,vector<ll>(h+10));
cin >> n;
for(int i=1;i<=n;i++)
{
ll x,y,a,b;
cin >> x >> y >> a >> b;
add(x,y,a,b);
}
for(int i=1;i<=w;i++)
{
for(int j=1;j<=h;j++)
{
p2[i][j]+=p2[i-1][j-1];
}
}
for(int i=1;i<=w;i++)
{
for(int j=h;j>=1;j--)
{
p3[i][j]+=p3[i-1][j+1];
}
}
for(int i=1;i<=w;i++)
{
for(int j=1;j<=h;j++)
{
p2[i][j]+=p3[i][j];
}
}
for(int i=1;i<=w;i++)
{
for(int j=1;j<=h;j++)
{
p2[i][j]+=p2[i-1][j];
}
}
for(int i=1;i<=w;i++)
{
for(int j=1;j<=h;j++)
{
p2[i][j]+=p2[i][j-1];
}
}
for(int i=1;i<=w;i++)
{
for(int j=1;j<=h;j++) p1[i][j]+=p1[i-1][j];
}
for(int i=1;i<=w;i++) for(int j=1;j<=h;j++) p1[i][j]+=p1[i][j-1];
for(int i=1;i<=w;i++) for(int j=1;j<=h;j++) p1[i][j]+=p2[i][j];
for(int i=1;i<=w;i++)
{
for(int j=1;j<=h;j++)
{
p1[i][j]+=p1[i-1][j]+p1[i][j-1]-p1[i-1][j-1];
}
}
ll q;
cin >> q;
for(int i=1;i<=q;i++)
{
ll x1,y1,x2,y2;
cin >> x1 >> y1 >> x2 >> y2;
ll sum=get(x1,y1,x2,y2);
ll sz=(x2-x1+1)*(y2-y1+1);
cout << sum/sz+(sum%sz>=(sz+1)/2)<<'\n';
}
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
754 ms |
881072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
695 ms |
880872 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
58 ms |
61008 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
72 ms |
89476 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
787 ms |
881744 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
396 ms |
353472 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
136 ms |
61568 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
275 ms |
200804 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
869 ms |
882312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
829 ms |
882488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
253 ms |
64080 KB |
Output is correct |
2 |
Correct |
231 ms |
68688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
237 ms |
63572 KB |
Output is correct |
2 |
Correct |
251 ms |
69320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
197 ms |
66740 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
181 ms |
63584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |