#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
typedef long long ll;
typedef long double ld;
vector<vector<ll>> v;
int n,m,k,q;
int nradds=0;
void add(int x1,int y1,int x2,int y2,ll val)
{
nradds++;
x1=max(x1,1);
y1=max(y1,1);
x2=min(x2,n);
y2=min(y2,m);
v[x1][y1]+=val;
v[x2+1][y1]-=val;
v[x1][y2+1]-=val;
v[x2+1][y2+1]+=val;
}
ll getsum(int x1,int y1,int x2,int y2)
{
return v[x2][y2]-v[x1-1][y2]-v[x2][y1-1]+v[x1-1][y1-1];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m>>k;
v.resize(n+5);
for(int i=0;i<=n+4;i++)
v[i].resize(m+5);
assert(k*max(n,m)<=1e8);
for(int z=1;z<=k;z++)
{
int x,y,a,b;
cin>>x>>y>>a>>b;
int nr=a;
int x1=x,y1=y,x2=x,y2=y;
int cnt=0;
while(nr>0&&cnt<=max(n,m))
{
add(x1,y1,x2,y2,b);
nr-=b;
cnt++;
x1--;
x2++;
y1--;
y2++;
if(x1<=0&&y1<=0&&x2>n&&y2>m)
break;
}
//cout<<v[1][1]<<' ';
x1++;
x2--;
y1++;
y2--;
add(x1,y1,x2,y2,a);
add(x1,y1,x2,y2,-cnt*b);
}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
v[i][j]+=v[i-1][j]+v[i][j-1]-v[i-1][j-1];
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
v[i][j]=v[i][j]+v[i-1][j]+v[i][j-1]-v[i-1][j-1];
//cout<<s[i][j]<<' ';
}
//assert(nradds<=k*max(n,m));
cin>>q;
while(q--)
{
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
ll suma=getsum(x1,y1,x2,y2);
ll cells=(y2-y1+1)*(x2-x1+1);
ll rez=round(ld(suma)/ld(cells));
cout<<rez<<'\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
935 ms |
215484 KB |
Output is correct |
2 |
Correct |
62 ms |
4592 KB |
Output is correct |
3 |
Correct |
56 ms |
3796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
880 ms |
215524 KB |
Output is correct |
2 |
Correct |
60 ms |
4544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
20180 KB |
Output is correct |
2 |
Correct |
58 ms |
2656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
24768 KB |
Output is correct |
2 |
Correct |
61 ms |
2628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
514 ms |
217724 KB |
Output is correct |
2 |
Correct |
72 ms |
2968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
841 ms |
92180 KB |
Output is correct |
2 |
Correct |
61 ms |
4540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
22504 KB |
Output is correct |
2 |
Correct |
65 ms |
2892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
490 ms |
45696 KB |
Output is correct |
2 |
Correct |
61 ms |
2632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
304 ms |
436936 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
313 ms |
436860 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
26 ms |
40888 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
26 ms |
40492 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1090 ms |
21068 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
25 ms |
40916 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |