9 条题解

  • 1
    @ 2026-4-17 20:24:55

    #include <bits/stdc++.h> using namespace std;

    const int N = 1e3 + 5; long long n,m,p,q,x,y,xx,yy,z; long long d[N][N],a[N][N],s[N][N];

    int main() { cin>>n>>m>>p>>q;

    for(int i=1;i<=n;i++)
    { 
    	for(int j=1;j<=m;j++)
    	{ 
    		cin>>a[i][j]; 
    		d[i][j] = a[i][j] - a[i-1][j] - a[i][j-1] + a[i-1][j-1]; 
    	} 
    }
    
    while(p--)
    {
    	cin>>x>>y>>xx>>yy>>z;
    	d[x][y] += z;
    	d[x][yy+1] -= z;
    	d[xx+1][y] -= z;
    	d[xx+1][yy+1] += z;
    }
    
    for(int i=1;i<=n;i++)
    {
    	for( int j=1;j<=m;j++)
    	{
    		a[i][j] = a[i-1][j] + a[i][j-1] - a[i-1][j-1] + d[i][j];
    		s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + a[i][j];
    		cout<<a[i][j]<<" ";
    	}
    	cout<<endl;
    }
    
    while(q--)
    {
    	cin>>x>>y>>xx>>yy;
    	cout<<s[xx][yy] - s[x-1][yy] - s[xx][y-1] + s[x-1][y-1]<<endl;
    }
    return 0;
    

    }

    信息

    ID
    1285
    时间
    1000ms
    内存
    256MiB
    难度
    7
    标签
    递交数
    811
    已通过
    177
    上传者