题目链接 thttps://codeforces.com/problemset/problem/1195/E
题目大意:
对于一个二维数组g[n][m], 在一个点(i, j)上往右下方圈一个 a*b size的矩阵,即我们的矩阵是点(i,j)到(i + a - 1, j + b - 1)矩阵中二维数组g有一个最小值,问,我们遍历完所有的(i, j)求出所有最小值的和;
//一开始,用静态线段树与ST表,与单调栈结合, 结果
//绷不住了 T T
//后面用了二维单调队列AC了
// AC CODE:
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
const ll maxn = 9e6;
const ll N = 3e3+10;
const ll inf = 1e18;
ll val[N];
ll qh[N][N];
vector<ll>gr;
ll g[N][N];
void init(ll n, ll m, ll b){
for(ll d = 1; d <= n; d++){
deque<ll>q; ll cnt = 0;
for(ll i = 1; i <= m; i++){
if(!q.empty() && q.front() < i - b + 1){
q.pop_front();
}
while(!q.empty() && g[d][i] < g[d][q.back()]){
q.pop_back();
}
q.push_back(i);
if(i > b - 1) qh[d][++cnt] = g[d][q.front()];
}
}
}
signed main(){
ll n, m, a, b;
ll x, y, z;
cin>>n>>m>>a>>b;
gr.resize(n*m + 10);
cin>>gr[1]>>x>>y>>z;
// 以下为输入操作
for(ll i = 1; i <= n; i++){
for(ll j = 1; j <= m; j++){
ll cnt = (i - 1)*m+j;
if(cnt == 1){
g[i][j] = gr[cnt];
continue;
}
gr[cnt] = (x*gr[cnt - 1] + y)%z;
g[i][j] = gr[cnt];
}
fill(qh[i], qh[i] + N, -1);
}
// 以上为输入操作
init(n, m, b);
ll ans = 0;
for(ll j = 1; j <= m - b + 1; j++){
for(ll i = 1; i <= n; i++){
if(qh[i][j] != -1) val[i] = qh[i][j];
}
deque<ll>tq;
for(ll i = 1; i <= n; i++){
if(!tq.empty() && i - a + 1 > tq.front()){
tq.pop_front();
}
while(!tq.empty() && val[i] < val[tq.back()]){
tq.pop_back();
}
tq.push_back(i);
if(i > a - 1) ans += val[tq.front()];
}
}
cout<<ans<<endl;
return 0;
}
//最后附上单调队列的板子代码 ^ ^:
deque<ll>tq;
for(ll i = 1; i <= n; i++){
if(!tq.empty() && i - a + 1 > tq.front()){
tq.pop_front();
}
while(!tq.empty() && val[i] < val[tq.back()]){
tq.pop_back();
}
tq.push_back(i);
if(i > a - 1) ans += val[tq.front()];
}