ZOJ 1636 Evaluate Matrix Sum

大水题。。。

 

#include <cstdio>

#include <cstring>

using namespace std;

#define N 505

int s[N][N], n, m, l[N];



int main() {

    int T;

    scanf("%d", &T);

    for (int cas=1; cas<=T; cas++) {

        printf("Case %d:\n", cas);

        scanf("%d%d", &n, &m);

        memset(s, 0, sizeof(s));

        memset(l, 0, sizeof(l));



        int a;

        for (int i=1; i<=n; i++)

            for (int j=1; j<=m; j++) {

                scanf("%d", &a);

                l[j] += a*a;

                s[i][j] = s[i][j-1] + l[j];

            }

        int r1, r2, c1, c2;

        scanf("%d", &a);

        while (a--) {

            scanf("%d%d%d%d", &r1, &c1, &r2, &c2);

            printf("%d\n", s[r2][c2]-s[r2][c1-1]-s[r1-1][c2]+s[r1-1][c1-1]);

        }

    }

    return 0;

}


 

 

你可能感兴趣的:(Matrix)