#P9563. [SDCPC2023] Be Careful 2

[SDCPC2023] Be Careful 2

题目背景

警告:滥用本题评测将被封禁。

题目描述

Little Cyan Fish has an n×mn \times m rectangle located in a plane. The top-right corner of the rectangle is at (n,m)(n, m), while the bottom-left corner is at (0,0)(0, 0). There are kk banned points inside the rectangle. The ii-th banned point is located at (xi,yi)(x_i, y_i).

Little Cyan Fish would like to draw a square inside the rectangle. However, he dislikes all the banned points, so there cannot be any banned points inside his square. Formally, Little Cyan Fish can draw a square with the bottom-left corner at (x,y)(x, y) and a side length dd if and only if:

  • Both xx and yy are non-negative integers while dd is a positive integer.
  • 0x<x+dn0 \leq x < x+d \leq n.
  • 0y<y+dm0 \leq y < y+d \leq m.
  • For each 1ik1 \leq i \leq k, the following condition must NOT be met:
    • x<xi<x+dx < x_i < x+d and y<yi<y+dy < y_i < y+d.

Please calculate the sum of the areas of all the squares that Little Cyan Fish can possibly draw. Since the answer could be huge, you need to output it modulo 998244353998244353.

输入格式

The is only one test case in each test file.

The first line of the input contains three integers nn, mm and kk (2n,m1092 \leq n,m \leq 10^9, 1k5×1031 \leq k \leq 5 \times 10^3) indicating the size of the rectangle and the number of banned points.

For the following kk lines, the ii-th line contains two integers xix_i and yiy_i (0<xi<n0 < x_i < n, 0<yi<m0 < y_i < m) indicating the position of the ii-th banned point. It is guaranteed that all the banned points are distinct.

输出格式

Output one line containing one integer indicating the answer modulo 998244353998244353.

题目大意

【题目描述】

小青鱼有一个位于二维平面上的,大小为 n×mn \times m 的矩形。矩形的右上角位于 (n,m)(n, m),而左下角位于 (0,0)(0, 0)。矩形内部有 kk 个禁止点,第 ii 个禁止点位于 (xi,yi)(x_i, y_i)

小青鱼想在矩形里画一个正方形。但由于小青鱼不喜欢禁止点,因此正方形的内部不能有任何禁止点。更正式地,小青鱼可以画一个左下角位于 (x,y)(x, y) 且边长为 dd 的正方形,当且仅当:

  • xxyy 都是非负整数,dd 是一个正整数。
  • 0x<x+dn0 \leq x < x+d \leq n
  • 0y<y+dm0 \leq y < y+d \leq m
  • 每个 1ik1 \leq i \leq k不能 满足以下条件:
    • x<xi<x+dx < x_i < x+dy<yi<y+dy < y_i < y+d

请计算小青鱼可以画的正方形的总面积。由于答案可能很大,请将答案对 998244353998244353 取模后输出。

【输入格式】

每个测试文件仅有一组测试数据。

第一行输入三个整数 nnmmkk2n,m1092 \leq n,m \leq 10^91k5×1031 \leq k \leq 5 \times 10^3),表示矩形的大小和禁止点的数量。

对于接下来 kk 行,第 ii 行输入两个整数 xix_iyiy_i0<xi<n0 < x_i < n0<yi<m0 < y_i < m)表示第 ii 个禁止点的位置。保证所有禁止点互不相同。

【输出格式】

输出一行一个整数,代表对 998244353998244353 取模后的答案。

【样例解释】

对于第一组样例数据,小青鱼有 1212 种方式画一个正方形,如下图所示。

共有 99 个边长为 11 的正方形和 33 个边长为 22 的正方形。因此答案为 9×12+3×22=219 \times 1^2 + 3 \times 2^2 = 21

以下画正方形的方式是不合法的,因为正方形内有一个禁止点。

3 3 1
2 2

21

5 5 2
2 1
2 4

126

提示

For the first sample test case, Little Cyan Fish has 1212 ways to draw a square, illustrated as follows.

There are 99 squares of side length 11 and 33 squares of side length 22. So the answer is 9×12+3×22=219 \times 1^2 + 3 \times 2^2 = 21.

Note that the following plans are invalid since there's a banned point in the square.