#P10714. 【MX-X1-T2】「KDOI-05」简单的有限网格问题

【MX-X1-T2】「KDOI-05」简单的有限网格问题

Background

Original problem link: https://oier.team/problems/X1B.

Problem Description

Player S is playing a mini game. In the game, there is an n×mn\times m chessboard, and there are stars on kk cells. Initially, there is a catcher at position (x,y)(x,y). In each operation, you can move the catcher to some cell in the same row or the same column, such that the new position is different from the old one, and the new position (x,y)(x',y') must satisfy 1xn1\leq x'\leq n, 1ym1\leq y'\leq m. The catcher will capture all stars on the path from (x,y)(x,y) to (x,y)(x',y'). After a star is captured, it disappears.

The goal of the game is to get as many stars as possible in exactly two moves. However, player S does not know how to play, so each time he randomly picks a new position that the catcher can move to. Among the (n+m2)2(n+m-2)^2 different move plans of player S, find the sum of the numbers of stars captured. Output the answer modulo 109+710^9+7.

Input Format

The first line contains three positive integers n,m,kn,m,k, representing the board size and the number of stars.

The second line contains two positive integers x,yx,y, representing the initial position of the catcher.

The next kk lines each contain two positive integers, representing the position (p,q)(p,q) of each star. There may be multiple stars on the same cell.

Output Format

One line with one non-negative integer, representing the sum, over all (n+m2)2(n+m-2)^2 different move plans of player S, of the number of stars he can capture, modulo 109+710^9+7.

3 3 4
2 2
1 1
1 2
1 3
3 1

11
5 8 9
2 7
1 7
2 2
4 7
4 5
4 7
2 8
5 2
1 7
1 7
153

Hint

[Sample Explanation #1]

On the grid, one valid plan to move the catcher is:

(2,2)(1,2)(1,3)(2,2)\to(1,2)\to(1,3)

In this plan, it can capture 11 star at (1,2)(1,2) and 11 star at (1,3)(1,3).

[Constraints]

This problem uses bundled testdata.

Subtask ID Score nn\leq mm\leq
11 55 5050
22 1010 10001000
33 2020 10510^5 10510^5
44 2525 10910^9
55 10910^9
66 1515 101810^{18}

For 100%100\% of the data, 1k1051\leq k\leq10^5, 1n,m10181\leq n,m\leq10^{18}, 1x,pn1\leq x,p\leq n, 1y,qm1\leq y,q\leq m, (x,y)(p,q)(x,y)\neq(p,q).

Translated by ChatGPT 5