問題一覧 > 通常問題

No.755 Zero-Sum Rectangle

レベル : / AI推定難易度 : 925 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 130
作問者 : tatyam / テスター : Shuz*
お気に入りにしたユーザー ProblemId : 2553 / 自分の提出
問題文最終更新日: 2022-05-02 00:11:33
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
Advent Calendar Contest 2018 (順位表) の他の問題:

Problem Statement

There is a square $A$ of $M \times M$ cells. Each cell of $A$ has a value, and the value of cell $(i,j)$ is $A_{i,j}$.
For each $(x_i,y_i)$, Pokan Kaiko DP wants to count the non-empty rectangular regions in $A$ that contain cell $(x_i,y_i)$ and whose sum is $0$.
Note that what is counted here is the ways of choosing a rectangular region. That is, even if $2$ rectangular regions contain the same numbers, they are counted separately if their positions differ.

Input

$N\ M$
$A_{1,1} \cdots A_{1,M}$
$\hspace{6pt}\vdots$
$A_{M,1} \cdots A_{M,M}$
$x_1\ \ y_1$
$\hspace{3pt}\vdots$
$x_N\ \ y_N$
  • $1≤N≤10$
  • $1≤M≤130$
  • $-10^9≤A_{i,j}≤10^9$
  • $1≤x_i,y_i≤M$
  • All input values are integers.

In addition, there is an evil case with $N = 1300$. This test case does not affect the submission result.

Output

For each $(x_i,y_i)$, output the number of non-empty rectangular regions in $A$ that contain cell $(x_i,y_i)$ and whose sum is $0$.

Sample

Sample 1
Input
4 4
0 -1 5 5
-3 3 0 -3
5 -1 -5 4
-4 4 -5 0
2 4
4 1
4 3
2 2
Output
2
1
1
5

When $x_i=2,y_i=4$, the $2$ rectangles $(2,1),(3,4)$ and $(2,2),(2,4)$ satisfy the condition, so output $2$.
When $x_i=4,y_i=1$, the $1$ rectangle $(4,1),(4,2)$ satisfies the condition, so output $1$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。