A12673 | OpenStreetMap
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Seryozha conducts a course dedicated to building a map of heights of Stepanovo recreation center. He laid a rectangle grid of size $n \times m$ cells on a map (rows of grid are numbered from $1$ to $n$ from north to south, and columns are numbered from $1$ to $m$ from west to east). After that he measured the average height of each cell above Rybinsk sea level and obtained a matrix of heights of size $n \times m$ . The cell $(i, j)$ lies on the intersection of the $i$ -th row and the $j$ -to column and has height $h_{i, j}$ .
Seryozha is going to look at the result of his work in the browser. The screen of Seryozha's laptop can fit a subrectangle of size $a \times b$ of matrix of heights ( $1 \le a \le n$ , $1 \le b \le m$ ). Seryozha tries to decide how the weather can affect the recreation center — for example, if it rains, where all the rainwater will gather. To do so, he is going to find the cell having minimum height among all cells that are shown on the screen of his laptop.
Help Seryozha to calculate the sum of heights of such cells for all possible subrectangles he can see on his screen. In other words, you have to calculate the sum of minimum heights in submatrices of size $a \times b$ with top left corners in $(i, j)$ over all $1 \le i \le n - a + 1$ and $1 \le j \le m - b + 1$ .
Consider the sequence $g_i = (g_{i - 1} \cdot x + y) \bmod z$ . You are given integers $g_0$ , $x$ , $y$ and $z$ . By miraculous coincidence, $h_{i, j} = g_{(i - 1) \cdot m + j - 1}$ .
Seryozha is going to look at the result of his work in the browser. The screen of Seryozha's laptop can fit a subrectangle of size $a \times b$ of matrix of heights ( $1 \le a \le n$ , $1 \le b \le m$ ). Seryozha tries to decide how the weather can affect the recreation center — for example, if it rains, where all the rainwater will gather. To do so, he is going to find the cell having minimum height among all cells that are shown on the screen of his laptop.
Help Seryozha to calculate the sum of heights of such cells for all possible subrectangles he can see on his screen. In other words, you have to calculate the sum of minimum heights in submatrices of size $a \times b$ with top left corners in $(i, j)$ over all $1 \le i \le n - a + 1$ and $1 \le j \le m - b + 1$ .
Consider the sequence $g_i = (g_{i - 1} \cdot x + y) \bmod z$ . You are given integers $g_0$ , $x$ , $y$ and $z$ . By miraculous coincidence, $h_{i, j} = g_{(i - 1) \cdot m + j - 1}$ .
输入格式
The first line of the input contains four integers $n$ , $m$ , $a$ and $b$ ( $1 \le n, m \le 3\,000$ , $1 \le a \le n$ , $1 \le b \le m$ ) — the number of rows and columns in the matrix Seryozha has, and the number of rows and columns that can be shown on the screen of the laptop, respectively.
The second line of the input contains four integers $g_0$ , $x$ , $y$ and $z$ ( $0 \le g_0, x, y < z \le 10^9$ ).
The second line of the input contains four integers $g_0$ , $x$ , $y$ and $z$ ( $0 \le g_0, x, y < z \le 10^9$ ).
输出格式
Print a single integer — the answer to the problem.
输入输出样例
输入 #1
3 4 2 1 1 2 3 59
输出 #1
111
The matrix from the first example:


C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted