#差分,前缀和#nssl 1469 U


分析

考虑离线,因为异或和很难在线处理
然后可以用两个数组来差分斜与横的情况,然后将答案竖着传
时间复杂度\(O(n^2)\)


代码

#include <cstdio>
#include <cctype>
#define rr register
using namespace std;
typedef long long lll;
const int N=1011;
int n; lll ans,s1[N][N],s2[N][N];
inline signed iut(){
	rr int ans=0; rr char c=getchar();
	while (!isdigit(c)) c=getchar();
	while (isdigit(c)) ans=(ans<<3)+(ans<<1)+(c^48),c=getchar();
	return ans;
}
signed main(){
	n=iut();
	for (rr int Q=iut();Q;--Q){
		rr int x=iut(),y=iut(),L=iut(),z=iut();
		s1[x][y]+=z; if (x+L>n) continue;
		s2[x+L][y]-=z; if (y+L>n) continue;
		s1[x+L][y+L]-=z; s2[x+L][y+L]+=z;
	}
	for (rr int i=1;i<n;++i)
	for (rr int j=1;j<n;++j)
	   s1[i+1][j+1]+=s1[i][j];
	for (rr int i=1;i<=n;++i)
	for (rr int j=1;j<n;++j)
	   s2[i][j+1]+=s2[i][j];
	for (rr int i=1;i<n;++i)
	for (rr int j=1;j<=n;++j)
	   s1[i+1][j]+=s1[i][j],
	       s2[i+1][j]+=s2[i][j];
	for (rr int i=1;i<=n;++i)
	for (rr int j=1;j<=n;++j)
	   ans^=s1[i][j]+s2[i][j];
	return !printf("%lld",ans);
}
posted @ 2020-08-12 21:11  lemondinosaur  阅读(82)  评论(0编辑  收藏  举报