QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 2048 MB Total points: 100

#12514. Odd-Even Blocks

Statistics

There is a $01$-matrix with $m$ rows and $n$ columns that contains exactly $t$ ones, and all of these ones are located in the same row. The row index where the ones are located is $r$, and the column indices are $c_1, c_2, \dots, c_t$. Please calculate the number of $k \times k$ submatrices that contain an odd number of zeros.

For example, in the $3 \times 4$ $01$-matrix shown below, there are $3$ submatrices of size $2 \times 2$ that contain an odd number of zeros, as indicated by the blue submatrices. The red $2 \times 2$ submatrix contains $4$ zeros, so it is not included in the count.

Input

m n
t k r
c_1 c_2 ... c_t
  • $m, n$ are the number of rows and columns of the matrix, respectively.
  • $t$ is the number of ones.
  • $k$ is the size of the submatrix.
  • $r$ is the row index where the $t$ ones are located.
  • $c_1, c_2, \dots, c_t$ are the column indices of the ones, and it is guaranteed that $c_i < c_{i+1}$.

Output

x

A single integer $x$, representing the number of $k \times k$ submatrices containing an odd number of zeros.

Constraints

  • $1 \le m, n \le 10^9$.
  • $0 \le t \le \min(n, 10^5)$.
  • $1 \le k \le \min(m, n)$.
  • $1 \le r \le m$.
  • $1 \le c_i \le n$.
  • All input numbers are integers.

Examples

Input 1

3 4
2 2 1
2 4

Output 1

3

Input 2

4 5
3 3 3
1 3 4

Output 2

6

Subtasks

This problem consists of three subtasks. The conditions are as follows. Each subtask may contain one or more test cases, and all test cases in a subtask must be answered correctly to receive the points for that subtask.

Subtask Points Additional Constraints
1 11 $m, n \le 1000$
2 41 $m, n \le 10^5$
3 48 No additional constraints

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.