#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
#define int long long
using namespace std;
typedef long long ll;
typedef long double ld;
vector<vector<ll>> v,S1,S2;
int n,m,k,q;
int nradds=0;
void add(int x1,int y1,int x2,int y2,ll val)
{
x1=max(x1,1LL);
y1=max(y1,1LL);
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];
}
ll put[2][2500005];
ll s[2500005];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m>>k;
if(m==1)
{
for(int z=1;z<=k;z++)
{
ll x,y,a,b;
cin>>x>>y>>a>>b;
//assert(y==1);
ll nr=a/b;
put[0][x]+=a;
put[0][x+1]-=a;
ll st=x-nr;
ll dr=x-1;
if(dr>0)
{
st=max(st,1LL);
ll lg=dr-st+2;
put[0][st]+=a-lg*b;
put[0][dr+1]-=a-lg*b;
put[0][dr+1]-=(lg-1)*b;
put[1][st]+=b;
put[1][dr+1]-=b;
}
st=x+1;
dr=x+nr;
if(st<=n)
{
dr=min(dr,n*1LL);
ll lg=dr-st+2;
put[0][st]+=a;
put[0][dr+1]-=a;
put[0][dr+1]-=(lg-1)*(-b);
put[1][st]-=b;
put[1][dr+1]+=b;
}
}
ll suma=0;
for(int i=1;i<=n;i++)
{
suma+=put[0][i];
s[i]=suma;
}
ll si=0;
suma=0;
for(int i=1;i<=n;i++)
{
si+=put[1][i];
suma+=si;
s[i]+=suma;
}
for(int i=1;i<=n;i++)
s[i]+=s[i-1];
cin>>q;
while(q--)
{
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
//assert(y1==1&&y2==1);
ll val=s[x2]-s[x1-1];
ll rez=round(ld(val)/ld(x2-x1+1));
cout<<rez<<'\n';
}
return 0;
}
v.resize(n+5);
S1.resize(n+5);
S2.resize(n+5);
for(int i=0;i<=n+4;i++)
{
v[i].resize(m+5);
S1[i].resize(m+5);
S2[i].resize(m+5);
}
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=a/b;
/*if(cnt==0)
{
add(x,y,x,y,a);
continue;
}*/
x1=x-cnt;
x2=x+cnt;
y1=y-cnt;
y2=y+cnt;
add(x1,y1,x2,y2,a);
add(x1,y1,x2,y2,-(cnt+1)*b);
while(x1<=x)
{
add(x1,y1,x2,y2,b);
x1++;
y1++;
x2--;
y2--;
}
/*S1[x1][y1]+=b;
S1[x+1][y+1]-=b;
S1[x+1][y+1]+=b;
S1[x2+2][y2+2]-=b;
if(y2+1<=m)
S2[x1][y2+1]-=b;
else
S2[x1+1][y2]-=b;
S2[x+1][y]+=b;
S2[x+1][y]-=b;
S2[x2+2][y1-1]+=b;*/
}
for(int i=1;i<=n;i++)
{
ll x=i,y=1;
ll suma=0;
while(x<=n&&y<=m)
{
suma+=S1[x][y];
v[x][y]+=suma;
x++;
y++;
}
}
for(int j=2;j<=m;j++)
{
ll x=1,y=j;
ll suma=0;
while(x<=n&&y<=m)
{
suma+=S1[x][y];
v[x][y]+=suma;
x++;
y++;
}
}
for(int i=1;i<=n;i++)
{
ll x=i,y=m;
ll suma=0;
while(x<=n&&y>0)
{
suma+=S2[x][y];
v[x][y]+=suma;
x++;
y--;
}
}
for(int j=1;j<m;j++)
{
ll x=1,y=j;
ll suma=0;
while(x<=n&&y>0)
{
suma+=S2[x][y];
v[x][y]+=suma;
x++;
y--;
}
}
/*for(int i=1;i<=n;i++,cout<<'\n')
for(int j=1;j<=m;j++)
cout<<v[i][j]<<' ';*/
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++,cout<<'\n')
for(int j=1;j<=m;j++)
cout<<v[i][j]<<' ';*/
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;
}
Compilation message
nuclearia.cpp: In function 'int main()':
nuclearia.cpp:108:13: warning: unused variable 'nr' [-Wunused-variable]
108 | int nr=a;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
20352 KB |
Output is correct |
2 |
Correct |
70 ms |
2644 KB |
Output is correct |
3 |
Correct |
57 ms |
2292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
20456 KB |
Output is correct |
2 |
Correct |
85 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
60128 KB |
Output is correct |
2 |
Correct |
84 ms |
4352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
111 ms |
73964 KB |
Output is correct |
2 |
Correct |
79 ms |
4640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
22180 KB |
Output is correct |
2 |
Correct |
94 ms |
2904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
113 ms |
11708 KB |
Output is correct |
2 |
Correct |
76 ms |
2676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
227 ms |
65356 KB |
Output is correct |
2 |
Correct |
84 ms |
4944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
973 ms |
135224 KB |
Output is correct |
2 |
Correct |
99 ms |
4300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
245 ms |
61416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
243 ms |
61400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
781 ms |
62056 KB |
Output is correct |
2 |
Execution timed out |
1087 ms |
63476 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1092 ms |
59604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1069 ms |
63044 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1082 ms |
60324 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |