将三角形化为梯形和矩形的和,差。
先用前缀和计算梯形、矩形的和即可。
ps:计算时注意f[a,b] = f[b] - f[a - 1]
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 3000 + 5;
int mp[maxn][maxn];
int tra[maxn][maxn],rect[maxn][maxn];
int n,m,q;
unsigned A,B,C;
typedef long long ll;
const ll mod = (1ll << 32);
void cal()
{
for(int i = 1;i <= n;i ++){
for (int j = m; j >= 1 ; j --) {
tra[i][j] = mp[i][j] + tra[i - 1][j + 1] + tra[i][j + 1] - tra[i - 1][j + 2];//梯形
rect[i][j] = mp[i][j] + rect[i - 1][j] + rect[i][j + 1] - rect[i - 1][j + 1];//矩形
}
}
}
int solve(int x,int y,int k)
{
return tra[x][y - k + 1] - tra[x - k][y + 1] - (rect[x][y + 1] - rect[x - k][y + 1]);
}
inline unsigned int rng61(){
A ^= A << 16;
A ^= A >> 5;
A ^= A << 1;
unsigned int t = A;
A = B;
B = C;
C ^= t ^ A;
return C;
}
int main()
{
scanf("%d%d%d%u%u%u", &n, &m, &q, &A, &B, &C);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
mp[i][j] = rng61();
cal();
int x,y,k;
ll sum = 0;
for(int i = 1; i <= q; i++){
x = rng61() % n + 1;
y = rng61() % m + 1;
k = rng61() % min(x, y) + 1;
sum = (sum * 233 + solve(x, y, k)) % mod;
}
printf("%lld\n",(sum + mod) % mod);
return 0;
}