#include using namespace std; using ll = long long; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> N >> M; ll H = M; ll W = M; FOR(i, 1, M+1){ FOR(j, 1, M+1){ cin >> A[i][j]; } } // 二次元累積和 // 横 FOR(i, 0, H+1){ FOR(j, 0, W+1){ A[i][j+1] += A[i][j]; } } // 縦 FOR(w, 0, W+1){ FOR(h, 0, H+1){ A[h+1][w] += A[h][w]; } } ll Q = N; while(Q--){ ll x, y; cin >> x >> y; ll count = 0; FOR(x0, 1, W+1){ FOR(x1, x0, W+1){ FOR(y0, 1, H+1){ FOR(y1, y0, H+1){ if(x0<=x && x<=x1 && y0<=y && y<=y1){ // x, yが縦と横どちらを指しているか注意 //ll sum = A[y1][x1] - A[y0-1][x1] - A[y1][x0-1] + A[y0-1][x0-1]; ll sum = A[x1][y1] - A[x0-1][y1] - A[x1][y0-1] + A[x0-1][y0-1]; if(sum==0){ count++; } } } } } } p(count); } return 0; }