CF1195E.OpenStreetMap
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Seryozha conducts a course dedicated to building a map of heights of Stepanovo recreation center. He laid a rectangle grid of size n×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×m. The cell (i,j) lies on the intersection of the i-th row and the j-th column and has height hi,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×b of matrix of heights (1≤a≤n, 1≤b≤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×b with top left corners in (i,j) over all 1≤i≤n−a+1 and 1≤j≤m−b+1.
Consider the sequence gi=(gi−1⋅x+y)modz. You are given integers g0, x, y and z. By miraculous coincidence, hi,j=g(i−1)⋅m+j−1 ((i−1)⋅m+j−1 is the index).
谢尔盖扎开设了一门课程,专门用于绘制斯捷潘诺沃度假中心的地形高程图。他在地图上铺设了一个 n×m 的矩形网格(网格的行从北向南编号为 1 到 n,列从西向东编号为 1 到 m)。随后,他测量了每个网格单元相对于梁赞海平面的平均海拔高度,从而获得一个大小为 n×m 的高程矩阵。单元格 (i,j) 位于第 i 行与第 j 列的交点处,其高度为 hi,j。
谢尔盖扎将在浏览器中查看他的工作成果。他的笔记本电脑屏幕最多可显示一个大小为 a×b 的高程矩阵子矩形(其中 1≤a≤n,1≤b≤m)。谢尔盖扎希望分析天气对度假中心的影响——例如,若下雨,雨水将汇集于何处。为此,他需要找出其屏幕上所显示的所有单元格中高度最小的那个单元格。
请帮助谢尔盖扎计算:对于所有他屏幕上可能显示的子矩形,其各自对应的高度最小值之和。换言之,你需要计算所有左上角位于 (i,j)、尺寸为 a×b 的子矩阵中的最小高度之和,其中 1≤i≤n−a+1,1≤j≤m−b+1。
考虑序列 gi=(gi−1⋅x+y)modz。已知整数 g0、x、y 和 z。奇妙的是,hi,j=g(i−1)⋅m+j−1(其中 (i−1)⋅m+j−1 为下标)。
输入格式
The first line of the input contains four integers n, m, a and b (1≤n,m≤3000, 1≤a≤n, 1≤b≤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 g0, x, y and z (0≤g0,x,y<z≤109).
输入的第一行包含四个整数 n、m、a 和 b(1≤n,m≤3000,1≤a≤n,1≤b≤m),分别表示 Seryozha 所拥有的矩阵的行数和列数,以及笔记本电脑屏幕可显示的行数和列数。
输入的第二行包含四个整数 g0、x、y 和 z(0≤g0,x,y<z≤109)。
输出格式
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:

第一个示例中的矩阵:

输入解题思路,AI测评打分。不知道怎么写?