303728: CF720D. Slalom

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Slalom

题意翻译

一个 $n \times m$ 的网格,其中有 $k$ 个矩形障碍,保证这些障碍不重叠。求从 $(1,1)$ 走到 $(n,m)$,每步只能往右或往上走,不经过任何障碍的方案数。 两种方案被视为不同,当且仅当存在一个障碍,它在第一种方案里被从右侧绕过,而在第二种方案里被从左侧绕过(第一种左,第二种右同理)。 $n, m \leq 10^6$,$k \leq 10^5$。

题目描述

Little girl Masha likes winter sports, today she's planning to take part in slalom skiing. The track is represented as a grid composed of $ n×m $ squares. There are rectangular obstacles at the track, composed of grid squares. Masha must get from the square $ (1,1) $ to the square $ (n,m) $ . She can move from a square to adjacent square: either to the right, or upwards. If the square is occupied by an obstacle, it is not allowed to move to that square. One can see that each obstacle can actually be passed in two ways: either it is to the right of Masha's path, or to the left. Masha likes to try all ways to do things, so she would like to know how many ways are there to pass the track. Two ways are considered different if there is an obstacle such that it is to the right of the path in one way, and to the left of the path in the other way. Help Masha to find the number of ways to pass the track. The number of ways can be quite big, so Masha would like to know it modulo $ 10^{9}+7 $ . The pictures below show different ways to pass the track in sample tests. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF720D/2ddedad82f8f5e28a322fd1fe426b1600d8a03dd.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF720D/c0dbe07c720846d8b66f7c06424a8cfd200c6af3.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF720D/f511984d971426f2757dbb61173a665800b3ee08.png)

输入输出格式

输入格式


The first line of input data contains three positive integers: $ n $ , $ m $ and $ k $ ( $ 3<=n,m<=10^{6} $ , $ 0<=k<=10^{5} $ ) — the size of the track and the number of obstacles. The following $ k $ lines contain four positive integers each: $ x_{1} $ , $ y_{1} $ , $ x_{2} $ , $ y_{2} $ ( $ 1<=x_{1}<=x_{2}<=n $ , $ 1<=y_{1}<=y_{2}<=m $ ) — coordinates of bottom left, and top right squares of the obstacle. It is guaranteed that there are no obstacles at squares $ (1,1) $ and $ (n,m) $ , and no obstacles overlap (but some of them may touch).

输出格式


Output one integer — the number of ways to pass the track modulo $ 10^{9}+7 $ .

输入输出样例

输入样例 #1

3 3 0

输出样例 #1

1

输入样例 #2

4 5 1
2 2 3 4

输出样例 #2

2

输入样例 #3

5 5 3
2 2 2 3
4 2 5 2
4 4 4 4

输出样例 #3

3

Input

题意翻译

一个 $n \times m$ 的网格,其中有 $k$ 个矩形障碍,保证这些障碍不重叠。求从 $(1,1)$ 走到 $(n,m)$,每步只能往右或往上走,不经过任何障碍的方案数。 两种方案被视为不同,当且仅当存在一个障碍,它在第一种方案里被从右侧绕过,而在第二种方案里被从左侧绕过(第一种左,第二种右同理)。 $n, m \leq 10^6$,$k \leq 10^5$。

加入题单

上一题 下一题 算法标签: