#abc311e. E - Defect-free Squares

    ID: 3137 传统题 1000ms 256MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>来源atcoder动态规划基础算法二分前缀和与差分

E - Defect-free Squares

Score : 475475 points

问题陈述

有一个 HH 行和 WW 列的网格。令 (i,j)(i, j) 表示网格中从上数第 ii 行、从左数第 jj 列的方格。

网格中的每个方格要么是空洞,要么不是。恰好有 NN 个空洞方格:(a1,b1),(a2,b2),,(aN,bN)(a_1, b_1), (a_2, b_2), \dots, (a_N, b_N)

当三元正整数组 (i,j,n)(i, j, n) 满足以下条件时,以 (i,j)(i, j) 为左上角、(i+n1,j+n1)(i + n - 1, j + n - 1) 为右下角的方格区域被称为无洞方块

  • i+n1Hi + n - 1 \leq H
  • j+n1Wj + n - 1 \leq W
  • 对于所有满足 0kn1,0ln10 \leq k \leq n - 1, 0 \leq l \leq n - 1 的非负整数对 (k,l)(k, l),方格 (i+k,j+l)(i + k, j + l) 都不是空洞。

请问网格中共有多少个无洞方块?

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There is a grid with HH rows and WW columns. Let (i,j)(i, j) denote the square at the ii-th row from the top and jj-th column from the left of the grid.
Each square of the grid is holed or not. There are exactly NN holed squares: (a1,b1),(a2,b2),,(aN,bN)(a_1, b_1), (a_2, b_2), \dots, (a_N, b_N).

When the triple of positive integers (i,j,n)(i, j, n) satisfies the following condition, the square region whose top-left corner is (i,j)(i, j) and whose bottom-right corner is (i+n1,j+n1)(i + n - 1, j + n - 1) is called a holeless square.

  • i+n1Hi + n - 1 \leq H.
  • j+n1Wj + n - 1 \leq W.
  • For every pair of non-negative integers (k,l)(k, l) such that 0kn1,0ln10 \leq k \leq n - 1, 0 \leq l \leq n - 1, square (i+k,j+l)(i + k, j + l) is not holed.

How many holeless squares are in the grid?

Constraints

  • 1H,W30001 \leq H, W \leq 3000
  • 0Nmin(H×W,105)0 \leq N \leq \min(H \times W, 10^5)
  • 1aiH1 \leq a_i \leq H
  • 1biW1 \leq b_i \leq W
  • All (ai,bi)(a_i, b_i) are pairwise different.
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

HH WW NN

a1a_1 b1b_1

a2a_2 b2b_2

\vdots

aNa_N bNb_N

Output

Print the number of holeless squares.

Sample Input 1

2 3 1
2 3

Sample Output 1

6

There are six holeless squares, listed below. For the first five, n=1n = 1, and the top-left and bottom-right corners are the same square.

  • The square region whose top-left and bottom-right corners are (1,1)(1, 1).
  • The square region whose top-left and bottom-right corners are (1,2)(1, 2).
  • The square region whose top-left and bottom-right corners are (1,3)(1, 3).
  • The square region whose top-left and bottom-right corners are (2,1)(2, 1).
  • The square region whose top-left and bottom-right corners are (2,2)(2, 2).
  • The square region whose top-left corner is (1,1)(1, 1) and whose bottom-right corner is (2,2)(2, 2).

Sample Input 2

3 2 6
1 1
1 2
2 1
2 2
3 1
3 2

Sample Output 2

0

There may be no holeless square.

Sample Input 3

1 1 0

Sample Output 3

1

The whole grid may be a holeless square.

Sample Input 4

3000 3000 0

Sample Output 4

9004500500

update @ 2024/3/10 08:51:12