8 条题解

  • 9
    @ 2023-10-22 18:52:44

    哪个逼那么不要脸抄我代码

    点赞!!!

    #include <bits/stdc++.h> 
    using namespace std; 
    long long a[1010][1010],ans[1010][1010]; 
    int main() 
    { 
    	int n,m,k,t; 
    	cin>>n>>m>>k>>t; 
    	for(int i=1;i<=n;i++) 
    		for(int j=1;j<=m;j++) 
    		{ 
    			scanf("%lld",&a[i][j]); 
    			ans[i][j]=a[i][j]-a[i-1][j]-a[i][j-1]+a[i-1][j-1]; 
    		} 
    	while(k--) 
    	{ 
    		long x1,x2,y1,y2,num; 
    		scanf("%lld%lld%lld%lld%lld",&x1,&y1,&x2,&y2,&num); 
    		ans[x2+1][y2+1]+=num; 
    		ans[x1][y1]+=num; 
    		ans[x1][y2+1]-=num; 
    		ans[x2+1][y1]-=num; 
    	} 
    	for(int i=1;i<=n;i++) 
    	{ 
    		for(int j=1;j<=m;j++) 
    		{ 
    			ans[i][j]+=ans[i][j-1]+ans[i-1][j]-ans[i-1][j-1]; 
    			printf("%lld ",ans[i][j]);
    		} 
    		printf("\n"); 
    	} 
    	for(int i=1;i<=n;i++) 
    		for(int j=1;j<=m;j++) 
    		ans[i][j]+=ans[i][j-1]+ans[i-1][j]-ans[i-1][j-1]; 
    	while(t--) 
    	{ 
    		int x1,x2,y1,y2; 
    		scanf("%lld%lld%lld%lld",&x1 ,&y1,&x2,&y2); 
    		printf("%lld\n",ans[x2][y2]-ans[x1-1][y2]-ans[x2][y1-1]+ans[x1-1][y1-1]); 
    	} 
    	return 0; 
    }
    

    哪个逼那么不要脸抄我代码

    点赞!!!

    • 1
      @ 2023-10-29 17:40:11
      #include <bits/stdc++.h>
      using namespace std;
      const int N = 1e3 + 10;
      const int INF = 0x3f3f3f3f;
      long long n , m , p , q , x , y , x2 , y2 , z;
      long long cf[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]; 
      			cf[i][j] = a[i][j] - a[i-1][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;
      }
      
      • 0
        @ 2026-4-11 18:31:58

        #include <bits/stdc++.h> using namespace std; const int N = 1e3 + 10; const int INF = 0x3f3f3f3f; long long n , m , p , q , x , y , x2 , y2 , z; long long cf[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]; 
        		cf[i][j] = a[i][j] - a[i-1][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;
        

        }

        • 0
          @ 2026-4-11 18:31:16

          #include <bits/stdc++.h> using namespace std; long long a[1010][1010],ans[1010][1010]; int main() { int n,m,k,t; cin>>n>>m>>k>>t; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { scanf("%lld",&a[i][j]); ans[i][j]=a[i][j]-a[i-1][j]-a[i][j-1]+a[i-1][j-1]; } while(k--) { long x1,x2,y1,y2,num; scanf("%lld%lld%lld%lld%lld",&x1,&y1,&x2,&y2,&num); ans[x2+1][y2+1]+=num; ans[x1][y1]+=num; ans[x1][y2+1]-=num; ans[x2+1][y1]-=num; } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { ans[i][j]+=ans[i][j-1]+ans[i-1][j]-ans[i-1][j-1]; printf("%lld ",ans[i][j]); } printf("\n"); } for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) ans[i][j]+=ans[i][j-1]+ans[i-1][j]-ans[i-1][j-1]; while(t--) { int x1,x2,y1,y2; scanf("%lld%lld%lld%lld",&x1 ,&y1,&x2,&y2); printf("%lld\n",ans[x2][y2]-ans[x1-1][y2]-ans[x2][y1-1]+ans[x1-1][y1-1]); } return 0; }

          • 0
            @ 2024-10-29 17:09:32
            #include <bits/stdc++.h>
            using namespace std;
            const int N = 1e3 + 10;
            const int INF = 0x3f3f3f3f;
            long long n , m , p , q , x , y , x2 , y2 , z;
            long long cf[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]; 
            			cf[i][j] = a[i][j] - a[i-1][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;
            }
            小鸟专属
            
            • 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;
              

              }

              • 0
                @ 2023-10-11 20:31:04

                #include #include #include #include using namespace std; const int N = 1e3 + 10; long long n , m , p , q , a[N][N] , s[N][N] , x , y , x2 , y2 , cf[N][N] , tmp; int main(){ cin >> n >> m >> 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-1][j] - a[i][j-1] + a[i-1][j-1]; } }

                while(p--)
                {
                	cin >> x >> y >> x2 >> y2;
                	cout << sum[x2][y2] - sum[x-1][y2] - sum[x2][y-1] + sum[x-1][y-1] << endl;
                	
                }
                
                return 0;
                

                }保存一下代码哈,晚点再发真代码

              • 0
                @ 2023-4-30 16:54:41

                #include<bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; long long a[1010][1010],ans[1010][1010]; int main() { int n,m,k,t; cin>>n>>m>>k>>t; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { scanf("%lld",&a[i][j]); ans[i][j]=a[i][j]-a[i-1][j]-a[i][j-1]+a[i-1][j-1]; } while(k--) { long long x1,x2,y1,y2,num; scanf("%lld%lld%lld%lld%lld",&x1,&y1,&x2,&y2,&num); ans[x2+1][y2+1]+=num; ans[x1][y1]+=num; ans[x1][y2+1]-=num; ans[x2+1][y1]-=num; } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { ans[i][j]+=ans[i][j-1]+ans[i-1][j]-ans[i-1][j-1]; printf("%lld ",ans[i][j]); } printf("\n"); } for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) ans[i][j]+=ans[i][j-1]+ans[i-1][j]-ans[i-1][j-1]; while(t--) { int x1,x2,y1,y2; scanf("%lld%lld%lld%lld",&x1 ,&y1,&x2,&y2); printf("%lld\n",ans[x2][y2]-ans[x1-1][y2]-ans[x2][y1-1]+ans[x1-1][y1-1]); } return 0; }

                • 1

                信息

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