Технокубок 2017 - Финал (только для онсайт-финалистов)
G
Andryusha and Nervous Barriers
Codeforces
2700
原题
← FH →
翻译中…

Andryusha has found a perplexing arcade machine. The machine is a vertically adjusted board divided into square cells. The board has $*w*$ columns numbered from $1$ to $*w*$ from left to right, and $*h*$ rows numbered from $1$ to $*h*$ from the bottom to the top.

翻译中…

Further, there are barriers in some of board rows. There are $*n*$ barriers in total, and $*i*$-th of them occupied the cells $*l*_{*i*}$ through $*r*_{*i*}$ of the row $*u*_{*i*}$. Andryusha recollects well that no two barriers share the same row. Furthermore, no row is completely occupied with a barrier, that is, at least one cell in each row is free.

翻译中…

The player can throw a marble to any column of the machine from above. A marble falls downwards until it encounters a barrier, or falls through the bottom of the board. A marble disappears once it encounters a barrier but is replaced by two more marbles immediately to the left and to the right of the same barrier. In a situation when the barrier is at an edge of the board, both marbles appear next to the barrier at the side opposite to the edge. More than one marble can occupy the same place of the board, without obstructing each other's movement. Ultimately, all marbles are bound to fall from the bottom of the machine.

翻译中…

image Examples of marble-barrier interaction.

翻译中…

Peculiarly, sometimes marbles can go through barriers as if they were free cells. That is so because the barriers are in fact alive, and frightened when a marble was coming at them from a very high altitude. More specifically, if a marble falls towards the barrier $*i*$ from relative height more than $*s*_{*i*}$ (that is, it started its fall strictly higher than $*u*_{*i*} + *s*_{*i*}$), then the barrier evades the marble. If a marble is thrown from the top of the board, it is considered to appear at height $(*h* + 1)$.

翻译中…

Andryusha remembers to have thrown a marble once in each of the columns. Help him find the total number of marbles that came down at the bottom of the machine. Since the answer may be large, print it modulo $10^{9} + 7$.

翻译中…

Input

翻译中…

The first line contains three integers $*h*$, $*w*$, and $*n*$ ($1 ≤ *h* ≤ 10^{9}$, $2 ≤ *w* ≤ 10^{5}$, $0 ≤ *n* ≤ 10^{5}$) — the number of rows, columns, and barriers in the machine respectively.

翻译中…

Next $*n*$ lines describe barriers. $*i*$-th of these lines containts four integers $*u*_{*i*}$, $*l*_{*i*}$, $*r*_{*i*}$, and $*s*_{*i*}$ ($1 ≤ *u*_{*i*} ≤ *h*$, $1 ≤ *l*_{*i*} ≤ *r*_{*i*} ≤ *w*$, $1 ≤ *s*_{*i*} ≤ 10^{9}$) — row index, leftmost and rightmost column index of $*i*$-th barrier, and largest relative fall height such that the barrier does not evade a falling marble. It is guaranteed that each row has at least one free cell, and that all $*u*_{*i*}$ are distinct.

翻译中…

Output

翻译中…

Print one integer — the answer to the problem modulo $10^{9} + 7$.

翻译中…

Note

翻译中…

In the first sample case, there is a single barrier: if one throws a marble in the second or the third column, two marbles come out, otherwise there is only one. The total answer is $7$.

翻译中…

In the second sample case, the numbers of resulting marbles are $2$, $2$, $4$, $4$, $4$ in order of indexing columns with the initial marble.

翻译中…

In the third sample case, the numbers of resulting marbles are $1$, $1$, $4$, $4$, $4$. Note that the first barrier evades the marbles falling from the top of the board, but does not evade the marbles falling from the second barrier.

翻译中…

In the fourth sample case, the numbers of resulting marbles are $2$, $2$, $6$, $6$, $6$, $6$, $6$, $6$, $6$, $1$, $2$, $1$, $1$, $1$, $1$. The picture below shows the case when a marble is thrown into the seventh column.

翻译中…

image The result of throwing a marble into the seventh column.

翻译中…

样例

Input #1
10 5 1
3 2 3 10
Output #1
7
InputCopy OutputCopy
Input #2
10 5 2
3 1 3 10
5 3 5 10
Output #2
16
InputCopy OutputCopy
Input #3
10 5 2
3 1 3 7
5 3 5 10
Output #3
14
InputCopy OutputCopy
Input #4
10 15 4
7 3 9 5
6 4 10 1
1 1 4 10
4 11 11 20
Output #4
53
InputCopy OutputCopy
题目信息
标签
数据结构
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。