/*
بسم الله الرحمن الرحيم
Author:
(:Muhammad Aneeq:)
*/
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <cmath>
using namespace std;
#define int long long
inline void solve()
{
int h,w;
cin>>h>>w;
int a[h][w]={};
int x;
cin>>x;
while (x--)
{
int i,j,y,z;
cin>>i>>j>>y>>z;
i--;j--;
a[i][j]+=y;
for (int k=0;k<y/z+(y%z!=0);k++)
{
if (i-k<0&&i+k>=h)
break;
for (int l=0;l<y/z+(y%z!=0);l++)
{
if (j-l<0&&j+l>=w)
break;
if (k==0&&l==0)
continue;
if (i-k>=0)
{
if (j-l>=0)
a[i-k][j-l]+=y-z*max(k,l);
if (j+l<w&&l!=0)
a[i-k][j+l]+=y-z*max(k,l);
}
if (i+k<h&&k!=0)
{
if (j-l>=0)
a[i+k][j-l]+=y-z*max(k,l);
if (j+l<w&&l!=0)
a[i+k][j+l]+=y-z*max(k,l);
}
}
}
}
long long pre[h+1][w+1]={};
for (int i=0;i<h;i++)
{
for (int j=0;j<w;j++)
{
pre[i+1][j+1]=pre[i+1][j]+pre[i][j+1]-pre[i][j]+a[i][j];
}
}
int q;
cin>>q;
while (q--)
{
int a,b,c,d;
cin>>a>>b>>c>>d;
int f=pre[c][d]-pre[c][b-1]-pre[a-1][d]+pre[a-1][b-1];
long double g=(c-a+1)*(d-b+1);
cout<<(long long)round(f/g)<<'\n';
}
}
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
299 ms |
58904 KB |
Output is correct |
2 |
Correct |
49 ms |
2644 KB |
Output is correct |
3 |
Correct |
45 ms |
2388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
312 ms |
59060 KB |
Output is correct |
2 |
Correct |
48 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
167 ms |
39448 KB |
Output is correct |
2 |
Correct |
47 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
40472 KB |
Output is correct |
2 |
Correct |
49 ms |
2596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
198 ms |
61268 KB |
Output is correct |
2 |
Correct |
53 ms |
2892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
324 ms |
26176 KB |
Output is correct |
2 |
Correct |
49 ms |
2848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
264 ms |
41808 KB |
Output is correct |
2 |
Correct |
51 ms |
3012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
288 ms |
22336 KB |
Output is correct |
2 |
Correct |
47 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1083 ms |
19800 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1069 ms |
19804 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1031 ms |
19800 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1039 ms |
19800 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1010 ms |
19800 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1029 ms |
19804 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |