Tag: getchar score + = STD-optimized RET fine space GETC
Ideas:
We can see this question, and we can think of one-dimensional difference at a glance.
However, this complexity is O (NQ), and obviously t
So how to optimize it?
We will find that in the difference ~ Within the L-1 range
The values added by the difference are the same as the X-axis, and the y-axis increases progressively.
The abscissa and ordinate values of the reduced values increase with 1 as the tolerances.
Then, we can divide the difference Array
Mark (R, c) (R, C + 1), (R + L, c) (R + L, C + l) each time.
Code:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#define rii register int i#define rij register int j#define int long long using namespace std;int cf1[2005][2005],cf2[2005][2005],x[2005][2005];int n,q,r,c,l,s;inline int rd(){ int y=0,f=1;char ch=getchar(); while(!isdigit(ch)) {f=ch==‘-‘?0:1;ch=getchar();} while(isdigit(ch)) {y=(y<<1)+(y<<3)+ch-‘0‘;ch=getchar();} return f?y:-y;}signed main(){ freopen("u.in","r",stdin); freopen("u.out","w",stdout); n=rd(),q=rd(); for(rii=1;i<=q;i++) { r=rd(),c=rd(),l=rd(),s=rd(); cf1[r][c]+=s; cf1[r+l][c]-=s; cf2[r][c+1]+=s; cf2[r+l][c+l+1]-=s; } for(rij=1;j<=n;j++) { for(rii=1;i<=n;i++) { cf1[i][j]+=cf1[i-1][j]; } } for(rii=1;i<=n;i++) { for(rij=1;j<=n;j++) { cf2[i][j]+=cf2[i-1][j-1]; } } for(rii=1;i<=n;i++) { for(rij=1;j<=n;j++) { x[i][j]+=x[i][j-1]+cf1[i][j]-cf2[i][j]; } } int ans=0; for(rii=1;i<=n;i++) { for(rij=1;j<=n;j++) { ans^=x[i][j]; } } printf("%lld",ans); return 0;}
T1 81101noip simulation competition T1