6 条题解

  • 0
    @ 2023-10-22 20:30:35

    #include <bits/stdc++.h> using namespace std; const int N=1e3+10;

    long long n,m,p,q,cf[N][N],a[N][N],s[N][N]; long long x,y,x2,y2,z;

    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]; cf[i][j]=a[i][j]-a[i][j-1]+a[i-1][j-1]; } }

    while(p--){
    	cin>>x>>y>>x2>>y2>>z;
    	cf[x][y]+=z;
    	cf[x][y2+1]-=z;
    	cf[x2+1][y]-=z;
    	cf[x2+1][y2+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]+cf[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>>x2>>y2;
    	cout<<s[x2][y2]-s[x-1][y2]-s[x2][y-1]+s[x-1][y-1]<<endl;
    }
    return 0;
    

    }

    信息

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