NOIP 模拟 $19\; \rm u$
题解 \(by\;zj\varphi\)
二维差分的题目
维护两个标记,一个向下传,一个向右下传;
对于每次更新,我们可以直接更新 \((r,c)+s,(r+l,c)-s\) ; \((r,c+1)-s,(r+l,c+l+1)+s\),每组的后一个都是为了消除影响
Code
#include<bits/stdc++.h>
#define ri register signed
#define p(i) ++i
using namespace std;
namespace IO{
char buf[1<<21],*p1=buf,*p2=buf;
#define gc() p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++
template<typename T>inline void read(T &x) {
ri f=1;x=0;register char ch=gc();
while(ch<'0'||ch>'9') {if (ch=='-') f=0;ch=gc();}
while(ch>='0'&&ch<='9') {x=(x<<1)+(x<<3)+(ch^48);ch=gc();}
x=f?x:-x;
}
}
using IO::read;
namespace nanfeng{
#define FI FILE *IN
#define FO FILE *OUT
template<typename T>inline T cmax(T x,T y) {return x>y?x:y;}
template<typename T>inline T cmin(T x,T y) {return x>y?y:x;}
typedef long long ll;
static const int N=2e3+7;
int n,q,r,c,l,s;
ll fg1[N][N],fg2[N][N],res;
inline int main() {
// FI=freopen("nanfeng.in","r",stdin);
// FO=freopen("nanfeng.out","w",stdout);
read(n),read(q);
for (ri i(1);i<=q;p(i)) {
read(r),read(c),read(l),read(s);
fg1[r][c]+=s,fg2[r][c+1]-=s;
fg1[r+l][c]-=s,fg2[r+l][c+l+1]+=s;
}
for (ri i(1);i<=n;p(i)) {
register ll fg=0;
for (ri j(1);j<=n;p(j)) {
fg+=fg1[i][j]+fg2[i][j];
res^=fg;
fg1[i+1][j]+=fg1[i][j];
fg2[i+1][j+1]+=fg2[i][j];
}
}
printf("%lld\n",res);
return 0;
}
}
int main() {return nanfeng::main();}