F.十字阵列
题目链接-F.十字阵列
解题思路
用3个数组a[N],b[N]和w[N][N],分别统计对行,列和行列重合的格子造成的伤害即可
附上代码
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
const int M=1e9+7;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
typedef long long ll;
typedef pair<int,int> PII;
ll w[2010][2010],a[N],b[N];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
ll n,m,h;
cin>>n>>m>>h;
for(ll i=1;i<=h;i++){
int x,y,z;
cin>>x>>y>>z;
w[x][y]+=z;a[x]+=z;b[y]+=z;
}
ll ans=0;
for(ll i=1;i<=n;i++){
for(ll j=1;j<=m;j++){
ans=(ans+(a[i]+b[j]-w[i][j])*(i+j)%M)%M;
}
}
cout<<ans<<endl;
return 0;
}